#include<bits/stdc++.h>
using namespace std;
int zhishu(int a11){
int a1=0;
if(a11==2||a11==3){
return 1;
}
else{
for(int i1=a11-1;i1>=2;i1--){
if(a11%i1==0){
a1=1;
}
}
if(a1==1){
return 0;
}else{
return 1;
}
}
}
int weishu(int a,int b){
int q1,q2,q3,q4,q5,q6,q7,q8;
switch (b) {
case 1:
q1=a%10;
return q1;
break;
case 2:
q2=((a%100)-(a%10))/10;
return q2;
break;
case 3:
q3=((a%1000)-(a%100))/100;
return q3;
break;
case 4:
q4=((a%10000)-(a%1000))/1000;
return q4;
break;
case 5:
q5=((a%100000)-(a%10000))/10000;
return q5;
break;
case 6:
q6=((a%1000000)-(a%100000))/100000;
return q6;
break;
case 7:
q7=((a%10000000)-(a%1000000))/1000000;
return q7;
break;
case 8:
q8=((a%100000000)-(a%10000000))/10000000;
return q8;
break;
}
}
int hwzs(int ab){
if(zhishu(ab)==0){
return 0;
}else{
if(10>ab&&ab>4){
return 1;
}
if(100>ab&&ab>9){
if(weishu(ab,2)==weishu(ab,1)){
return 1;
}
}
if(1000>ab&&ab>99){
if(weishu(ab,3)==weishu(ab,1)){
return 1;
}
}
if(10000>ab&&ab>999){
if(weishu(ab,4)==weishu(ab,1)&&weishu(ab,3)==weishu(ab,2)){
return 1;
}
}
if(100000>ab&&ab>9999){
if(weishu(ab,5)==weishu(ab,1)&&weishu(ab,4)==weishu(ab,2)){
return 1;
}
}
if(1000000>ab&&ab>99999){
if(weishu(ab,6)==weishu(ab,1)&&weishu(ab,5)==weishu(ab,2)&&weishu(ab,4)==weishu(ab,3)){
return 1;
}
}
if(10000000>ab&&ab>999999){
if(weishu(ab,7)==weishu(ab,1)&&weishu(ab,6)==weishu(ab,2)&&weishu(ab,5)==weishu(ab,3)){
return 1;
}
}
if(100000000>ab&&ab>9999999){
if(weishu(ab,8)==weishu(ab,1)&&weishu(ab,7)==weishu(ab,2)&&weishu(ab,6)==weishu(ab,3)&&weishu(ab,5)==weishu(ab,4)){
return 1;
}
}else{
return 0;
}
}
}
int main()
{
int l,n;
scanf("%d %d",&l,&n);
for(int ib=l;ib<n;ib++){
if(hwzs(ib)==1){
printf("%d\n",ib);
}
}
}