for p in range(2,7758): if(3**p-3)%p<1!=set(`p`)<=set('2357'):print p