import random def is_prime3(q,k=50): q=abs(q) if q==2:return True if q<2 or q&1 == 0:return False d=(q-1)>>1 while d&1==0:d>>=1 for i in range(k): a=random.randint(1,q-1) t=d y=pow(a,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 False return True 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 is_prime3(i - 8):print(14) else:print(8)