#include <bits/stdc++.h>
#include <string>
using namespace std;
bool judge_sushu(int num)
{
if (num == 1)
return false;
for (int i = 2; i <= sqrt(num); i++)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
bool judge_huiwen(string str)
{
int length = str.length();
if (length == 1)
{
return true;
}
else
{
int head = 0;
int tail = length - 1;
int count = 0;
if (length % 2 == 0)
{
if (str[head] == str[tail])
{
while (head != (length / 2))
{
head++;
tail--;
if (str[head] == str[tail])
count++;
}
if (count == length / 2)
return true;
else return false;
}
}
if (length % 2 != 0)
{
if (str[head] == str[tail])
{
while(head< (length / 2)-1)
{
head++;
tail--;
if(str[head]==str[tail])
count++;
}
if(count==(length/2)-1)
{
return true;
}
else
return false;
}
}
}
}
void all_number(int num1, int num2)
{
for(int i=num1;i<=num2;i++)
{
string str = to_string(i);
if(judge_huiwen(str))
{
if(judge_sushu(i))
cout <<i<< endl;
}
}
}
int main()
{
int a, b;
cin>>a>>b;
all_number(a,b);
}