#include<bits/stdc++.h>
using namespace std;
const int N=1e9+10;
long long cnt=0,p[N/10],zs[N/10];
void shsu(int n)
{
for(int i=2;i<=n;i++){
if(p[i]==0)zs[++cnt]=i;
for(int j=1;j<=cnt;j++){
long long m=zs[j]*i;
if(m>n)break;
p[m]=1;
if(i%zs[j]==0)break;
}
}
}
bool ishw(long long a)
{
long long s=0,n,y=a;
while(a>0){
n=a%10;
s=s*10+n;
a=a/10;
}
if(s==y)return 1;
else return 0;
}
int main()
{
long long a,b;
cin>>a>>b;
shsu(b+100);
for(int i=1;i<=cnt;i++){
if(zs[i]<a)continue;
if(zs[i]>b)break;
if(ishw(zs[i]))cout<<zs[i]<<endl;
}
return 0;
}