#include<iostream>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
bool zhishu(int x) {
if (x <= 3) return x > 1;
if (x % 6 != 1 && x % 6 != 5) return false;
for (int i = 5; i < sqrt(x); i = i + 6) {
if (x % i == 0 || x % (i + 2) == 0)
return false;
}
return true;
}
int main() {
int a, b, i, j;
string str;
cin >> a >> b;
for (i = a; i <= b; i++) {
if (zhishu(i)) {
stringstream ss;
ss << i;
ss >> str;
if (str.size() == 1)
cout << str << endl;
else {
if (str.size() % 2 == 0) {
for (j = 0; j < str.size() / 2; j++) {
if (str[j] != str[str.size() - 1 - j])
break;
}
if (j == str.size() / 2)
cout << str << endl;
}
else {
for (j = 0; j < str.size() / 2; j++) {
if (str[j] != str[str.size() - 1 - j])
break;
}
if(j==str.size()/2)
cout << str << endl;
}
}
}
}
return 0;
}