import random as s def p(q,k=50): d=(q-1)>>1 while d&1==0:d>>=1 while k: k-=1 t=d y=pow(s.randint(1,q-1),t,q) while t!=q-1 and y!=1 and y!=q-1: y=pow(y,2,q) t<<=1 if y!=q-1 and t&1==0:return 0 return 1 i=int(input()) if i==4:print(3) elif i==6:print(5) elif i==8 or i==9 or i== 10 or i==15 or i==16 or i==22:print(7) elif i==12:print(11) elif i==14:print(13) elif i==20 or i==21:print(19) elif i==24 or i==25:print(23) elif (i-1)%8==0 and p(i-8):print(14) else:print(8)