#include<bits/stdc++.h>
using namespace std;
bool st[111111111], hashtable[111111111];
void Eratosthenes(int u){
for(int i = 2; i <= u; i++){
if(!st[i]){
hashtable[i] = true;
for(int j = i; j <= u; j += i) st[j] = true;
}
}
}
bool isPalindrome(int u){
string s = to_string(u);
string t(s.rbegin(), s.rend());
if(s == t) return true;
else return false;
}
bool ws(int u){
if(u >= 1000 and u < 10000) return false;
if(u >= 100000 and u < 1000000) return false;
if(u >= 10000000 and u < 100000000) return false;
return true;
}
int main(){
cin.tie(0)->sync_with_stdio(false);
int a, b;
cin >> a >> b;
if(a % 2 == 0) ++a;
Eratosthenes(b);
for(int i = a; i <= b; i += 2){
if(ws(i) == false) continue;
if(hashtable[i] and isPalindrome(i)) cout << i << endl;
}
return 0;
}