#include<iostream>
#include<cmath>
using namespace std;
bool hw(int n);
bool zs(int b){
int y=sqrt(b);
for(unsigned long i=2;i*i<=b;i++){
if(b%i==0){
return 0;
}
}
return 1;
}
bool hw(int a){
unsigned long n=a,e=0;
while(n!=0){
e=e*10+n%10;
n/=10;
}
if(e==a)return 1;
return 0;
}
int main()
{
unsigned long a,b;
cin>>a>>b;
for(unsigned long i=a;i<=b;i++)
{
if(hw(i)&&zs(i))
cout<<i<<endl;
}
return 0;
}