#include <bits/stdc++.h>
using namespace std;
const int N = 10001;
bitset<N> prim;
int main()
{
for(int i = 2; i * i <= N; ++i)
if(!prim[i])
for(int j = i + i; j <= N; j += i)
prim[j] = true;
for(int i = 1009; i <= 9973; i++)
if(!prim[i] && !prim[([=](int i) -> size_t { int sol = 0; while(i) sol = sol * 10 + i % 10, i /= 10; return sol; }(i))])
cout << i << ' ';
return 0;
}