#include<bits/stdc++.h>
using namespace std;
bool hw(int k)
{
int a[10],i;
for (i=0;k>0;i++)
{
a[i]=k%10;
k/=10;
}
for(int j=0;j<i;j++)
{
if(a[j]==a[i-j-1])
{
return true;
}
else
{
return false;
}
}
}
bool zs(int k)
{
for(int i=2;i*i<=k;i++)
{
if(k%i==0)
{
return false;
}
else
{
return true;
}
}
}
int main(){
int a,b;
cin>>a>>b;
for(;a<=b;a++)
{
if(hw(a)==true&&zs(a)==true)
{
cout<<a<<endl;
}
}
return 0;
}