from math import sqrt
def hanshu(a,b):
ls=[True]*(b+1)
c=int(sqrt(b))+1
d=2
while d<c:
if ls[d]==True:
for i in range(d+d,b+1,d):
ls[i]=False
d+=1
for i in range(a,b+1):
j=str(i)
if j==j[::-1]:
if ls[i]==True:
print(j)
a,b=map(int,input().split())
hanshu(a,b)