#include<stdio.h>
int a[110];
int prm(int x){
if(x==1)return 0;
if(x==2)return 1;
for(int i=2;i*i<=x;i++)
if(x%i==0)return 0;
return 1;
}int main(){
int i,j,k,x,y,p,f;
scanf("%d%d",&x,&y);
if(y>9989899)y=9989899;
if(x%2==0)x++;
if(y%2==0)y--;
for(i=x;i<=y;i+=2){
p=0;f=1;k=i;
while(k){
a[++p]=k%10;
k/=10;
}for(j=1;j<=p;j++)
if(a[j]!=a[p-j+1]){
f=0;break;
}if(f&&prm(i))printf("%d\n",i);
}return 0;
}
int a[110];
int prm(int x){
if(x==1)return 0;
if(x==2)return 1;
for(int i=2;i*i<=x;i++)
if(x%i==0)return 0;
return 1;
}int main(){
int i,j,k,x,y,p,f;
scanf("%d%d",&x,&y);
if(y>9989899)y=9989899;
if(x%2==0)x++;
if(y%2==0)y--;
for(i=x;i<=y;i+=2){
p=0;f=1;k=i;
while(k){
a[++p]=k%10;
k/=10;
}for(j=1;j<=p;j++)
if(a[j]!=a[p-j+1]){
f=0;break;
}if(f&&prm(i))printf("%d\n",i);
}return 0;
}