import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//http://p...content-available-to-author-only...j.com/problems/ZABAWA/
public class Main {
new Main().zadanie();
}
int x, y;
while ((s = in.readLine()) != null) {
tab = s.split(" ");
if (isPrime(x)) {
y++;
while (true) {
if (isPalidrome(y)) {
break;
} else {
y++;
}
}
} else {
y++;
while (true) {
if (isPalidrome(y)) {
break;
} else {
y--;
}
}
}
}
}
private boolean isPrime(int n) {
for (int i
= 2; i
< Math.
sqrt(n
)+1; i
++) { if (n % i == 0) {
return false;
}
}
return true;
}
private boolean isPalidrome(int n) {
return new StringBuilder(s).reverse().toString().equals(s) ? true : false;
}
}
CmltcG9ydCBqYXZhLmlvLkJ1ZmZlcmVkUmVhZGVyOwppbXBvcnQgamF2YS5pby5JT0V4Y2VwdGlvbjsKaW1wb3J0IGphdmEuaW8uSW5wdXRTdHJlYW1SZWFkZXI7CgovL2h0dHA6Ly9wLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5qLmNvbS9wcm9ibGVtcy9aQUJBV0EvCgpwdWJsaWMgY2xhc3MgTWFpbiB7CgoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgdGhyb3dzIElPRXhjZXB0aW9uIHsKCQluZXcgTWFpbigpLnphZGFuaWUoKTsKCX0KCglwcml2YXRlIHZvaWQgemFkYW5pZSgpIHRocm93cyBJT0V4Y2VwdGlvbiB7CgkJQnVmZmVyZWRSZWFkZXIgaW4gPSBuZXcgQnVmZmVyZWRSZWFkZXIobmV3IElucHV0U3RyZWFtUmVhZGVyKFN5c3RlbS5pbikpOwogICAgICAgIFN0cmluZyBzOwogICAgICAgIFN0cmluZ1tdIHRhYjsKICAgICAgICBpbnQgeCwgeTsKICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgd2hpbGUgKChzID0gaW4ucmVhZExpbmUoKSkgIT0gbnVsbCkgeyAKICAgICAgICAgICAgICAgIHRhYiA9IHMu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