def isPrime(n):
if n%2 == 0:
return False
for left in range(3,n,2):
if n % left == 0:
return False
return True
def palindrome(n):
result = []
max = 10**int(n/2)
left = int(max/10)
while left < max:
strLeft = str(left)
mid = 0
while mid < 10:
result.append(strLeft+str(mid)+strLeft[::-1])
mid+=1
left+=1
return result
def leftPalindrome(Left):
result = []
bl = int(l/2)
max = 10**bl
strLeft = Left[:bl]
strRevLeft = strLeft[::-1]
revLeft = int(strRevLeft)
left = int(strLeft)
right = int(Left[bl+1:])
mid = int(Left[bl])
if revLeft < right:
mid+=1
while mid < 10:
result.append(strLeft+str(mid)+strRevLeft)
mid+=1
left+=1
while left < max:
strLeft = str(left)
mid = 0
while mid < 10:
result.append(strLeft+str(mid)+strLeft[::-1])
mid+=1
left+=1
return result
def rightPalindrome(Right):
result = []
max = 10**int(len(Right)/2)
left = int(max/10)
while left < max:
strLeft = str(left)
mid = 0
while mid < 10:
r = strLeft+str(mid)+strLeft[::-1]
if int(r) > int(Right):
return result
result.append(r)
mid+=1
left+=1
return result
userStr = input()
two = userStr.split(' ')
min = two[0]
max = two[1]
allP = []
l = len(min)
l2 = len(max)
if l%2 != 0:
if l == 1:
allP+=list(range(int(min),10))
if l2 != l+1:
allP.append(11)
else:
allP += leftPalindrome(min)
for l in range(len(min)+2,len(max),2):
allP+=palindrome(l)
else:
if l == 2 and min <= 11:
allP.append(11)
for l in range(len(min)+1,len(max),2):
allP+=palindrome(l)
if l2%2 != 0:
allP += rightPalindrome(max)
for p in allP:
if isPrime(int(p)):
print(p)