def p(q): if q&1==0:return False return pow(2,q-1,q)==1 a=[0,0,0,0,3,0,5,0,7,7,7,0,11,0,13,7,7,0,8,0,19,19,7,0,23,23] x=input() if x<26:print a[x] elif (x-1)%8==0 and p(x-8):print 14 else:print 8