#include <bits/stdc++.h>
using namespace std;
bool zhi(int x){
for(int i=3;i*i<=x;i++){
if(x%i==0) return false;
}
return true;
}
bool hui(int x){
int k=x,w=0;;
while(k>0){
w=w*10+k%10;
k=k/10;
}
if(x==w) return true;
return false;
}
int main()
{
int a=0,b=0;
cin>>a>>b;
if(b>=9999999) b=9999999;
if(a%2==0) a++;
for(int i=a;i<=b;i=i+2){
if(zhi(i)==false) continue;
else if(hui(i)) printf("%d\n",i);
}
return 0;
}