#include<bits/stdc++.h>
using namespace std;
bool s(int j) {
if(j<=1) return false;
if(j==2) return true;
for(int i=2;i<=sqrt(j);i++){
if(j%i==0){
return false;
}
}
return true;
}
int main() {
int i;
for(i=1000; i<3000;i++){
if(s(i)&&s(i%10)&&s(i%100)&&s(i%1000)){
cout<<i<<endl;
}
}
return 0;
}
//1013
//1097
//1103
//1223
//1283
//1307
//1367
//1373
//1523
//1607
//1613
//1823
//1907
//1997
//2003
//2017
//2053
//2083
//2113
//2137
//2347
//2383
//2467
//2503
//2617
//2647
//2683
//2797
//2953
/**************************************************************
Problem: 1137
User: zhangziang
Language: C++
Result: Accepted
Time:5 ms
Memory:2072 kb
****************************************************************/