i=2 while i<2e4: if`i*pow(311,i-1,i)`==`i`[::-1]:print i i+=1