#include <bits/stdc++.h>
#define int long long
using namespace std;
// Hàm tà đạo :)
bool isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
signed main() {
string T;
cin >> T;
int a = T.length();
int nguyenthanhluu = -1;
for (int i = 0; i < a; i++) {
int ngu = 0;
for (int j = i; j < a; j++) {
if (T[j] < '0' || T[j] > '9') break;
ngu = ngu * 10 + (T[j] - '0');
if (ngu >= 1e8) break;
if (isPrime(ngu) ) {
nguyenthanhluu = max(nguyenthanhluu,ngu);
}
}
}
cout << nguyenthanhluu << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZyAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKLy8gSMOgbSB0w6AgxJHhuqFvIDopCmJvb2wgaXNQcmltZShpbnQgbikgewogICAgaWYgKG4gPD0gMSkgcmV0dXJuIGZhbHNlOwogICAgaWYgKG4gPD0gMykgcmV0dXJuIHRydWU7CiAgICBpZiAobiAlIDIgPT0gMCB8fCBuICUgMyA9PSAwKSByZXR1cm4gZmFsc2U7CiAgICBmb3IgKGludCBpID0gNTsgaSAqIGkgPD0gbjsgaSArPSA2KSB7CiAgICAgICAgaWYgKG4gJSBpID09IDAgfHwgbiAlIChpICsgMikgPT0gMCkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQogICAgcmV0dXJuIHRydWU7Cn0Kc2lnbmVkIG1haW4oKSB7CiAgICBzdHJpbmcgVDsKICAgIGNpbiA+PiBUOwogICAgaW50IGEgPSBULmxlbmd0aCgpOwogICAgaW50IG5ndXllbnRoYW5obHV1ID0gLTE7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGE7IGkrKykgewogICAgICAgIGludCBuZ3UgPSAwOyAKICAgICAgICBmb3IgKGludCBqID0gaTsgaiA8IGE7IGorKykgewogICAgICAgICAgICBpZiAoVFtqXSA8ICcwJyB8fCBUW2pdID4gJzknKSBicmVhazsKICAgICAgICAgICAgbmd1ID0gbmd1ICogMTAgKyAoVFtqXSAtICcwJyk7CiAgICAgICAgICAgIGlmIChuZ3UgPj0gMWU4KSBicmVhazsKICAgICAgICAgICAgaWYgKGlzUHJpbWUobmd1KSApIHsKICAgICAgICAgICAgICAgIG5ndXllbnRoYW5obHV1ID0gbWF4KG5ndXllbnRoYW5obHV1LG5ndSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IG5ndXllbnRoYW5obHV1IDw8IGVuZGw7CiAgICByZXR1cm4gMDsKfQo=