#include<bits/stdc++.h>
using namespace std;
int summ=0;
bool cou(int x)
{
for(int i=2;i*i<=x;i++)
{
if(x%i==0) return false;
}
return true;
}
bool co(int x)
{
int a[20],flag=1;
while(x!=0)
{
a[flag]=x % 10;
x/=10;
flag++;
}
for(int i=1; i<=flag/2;i++)
if(a[i]!=a[flag-i]) return false;
return true;
}
int main()
{
int x,y;
cin>>x>>y;
for(int i=x;i<=y;i++)
{
if(co(i))
{
if(cou(i))
{
cout<<i<<endl;
}
}
}
return 0;
}