#include<bits/stdc++.h>
using namespace std;
int m,n,k;
bool ok(int x)
{
if(x==1) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin>>m>>n;
for(int i=m;i<=n;i++)
{
k=i;
if(ok(k))
{
while(k>0)
{
k=(k-k%10)/10;
if(ok(k) && k%10==k)
{
cout<<i<<endl;
break;
}
else break;
}
}
else continue;
}
return 0;
}