#include<iostream>
using namespace std;
int zss(int a)
{
if(a==2)
return 1;
if(a<2)
return 0;
if(a%2==0)
return 0;
for(int j=2;j<a;j++)
{
if(a%j==0)
return 0;
}
return 1;
}
int hws(int b)
{
int c,d=0;
c=b;
while(c>0)
{
d=d*10+c%10;
c=c/10;
}
if(d==b)
return 1;
else
return 0;
}
int n,m,i;
bool x=false;
int main()
{
cin>>n>>m;
if(n<=2)
{
cout<<"2";
x=true;
n=3;
}
if(n%2==0)
n++;
if(m%2==0)
m--;
for(i=n;i<m;i+=2)
{
if(zss(i)==0||hws(i)==0)
continue;
else
{
if(x==false)
x=true;
else
cout<<endl;
cout<<i;
}
}
return 0;
}