#include <stdio.h>
int rev(int n) {
int dig,rev=0;
while(n>0)
{
dig=n%10;
rev=rev*10+dig;
n/=10;
}
return rev;
}
int bins(int pr[],int e) {
int start=0,end=113,mid,flag=0;
while(start<end) {
mid=(start+end)/2;
if(e>pr[mid]) {
start=mid+1;
printf("l");
} else if(e<pr[mid]) {
end=mid-1;
printf("o");
} else if(e==pr[mid]) {
flag=1;
break;
}
}
if (flag==1)
return mid;
else
return 0;
}
int main() {
int j,i,N,revn,count,pr[]={2,3,5,7,11,101,131,151,181,
191,313,353,373,383,727,757,787,797,919,
929,10301,10501,10601,11311,11411,12421,12721,12821,13331,
13831,13931,14341,14741,15451,15551,16061,16361,16561,16661,
17471,17971,18181,18481,19391,19891,19991,30103,30203,30403,
30703,30803,31013,31513,32323,32423,33533,34543,34843,35053,
35153,35353,35753,36263,36563,37273,37573,38083,38183,38783,
39293,70207,70507,70607,71317,71917,72227,72727,73037,73237,
73637,74047,74747,75557,76367,76667,77377,77477,77977,78487,
78787,78887,79397,79697,79997,90709,91019,93139,93239,93739,
94049,94349,94649,94849,94949,95959,96269,96469,96769,97379,
97579,97879,98389,98689,1003001};
scanf("%d",&N);
if(N%2==0)
N--;
for(i=N;;i+=2) {
revn=rev(i);
if(i==revn) {
printf("\n%d",revn);
count=bins(pr,i);
if(count!=0)
break;
}
}
printf("\n%d",i);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgcmV2KGludCBuKSB7CiAgICBpbnQgZGlnLHJldj0wOwogICAgd2hpbGUobj4wKQogICAgewogICAgCWRpZz1uJTEwOwoJCXJldj1yZXYqMTArZGlnOwoJCW4vPTEwOwogICAgfQoJcmV0dXJuIHJldjsKfQoKaW50IGJpbnMoaW50IHByW10saW50IGUpIHsgCglpbnQgc3RhcnQ9MCxlbmQ9MTEzLG1pZCxmbGFnPTA7Cgl3aGlsZShzdGFydDxlbmQpIHsKCQltaWQ9KHN0YXJ0K2VuZCkvMjsKCQlpZihlPnByW21pZF0pIHsKC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