https://www.luogu.org/problemnew/show/P1217
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N=100000000+1000;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int prime[N];
bool pp[N];
int vis[N];
bool pd_h(int x)
{
int y=x,num=0;//int y=x,防止x被改变
while (y!=0)
{
num=num*10+y%10;//上一次数字的记录进位再加上下一位数
y/=10;
}
if (num==x) return 1;
else return 0;
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//scanf("%d",&n);
int a,b;
cin>>a>>b;
int cnt=0;
if(b>10000000) b=10000000;
for(int i=2;i<=b;i++)
{
if(!vis[i]) prime[cnt++]=i,pp[i]=1;
for(int j=0;j<cnt&&i*prime[j]<=b;j++)
{
vis[i*prime[j]]=i;
if(i%prime[j]==0) break;
}
}
for(int i=a;i<=b;i++)
{
if(i>10000000) break;
if(pd_h(i)&&pp[i]) printf("%d\n",i);
}
//cout << "Hello world!" << endl;
return 0;
}