import random def solve(x): x=x-1 while x%2==0: x>>=1 for l in range(0,30): r=random.randint(1,x-1) t=x y=pow(r,t,x) while t!=x-1 and y!=1 and y!=x-1: y=(y*y)%x t<<=1 if y!=x-1 and t&1==0: return False return True 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] else:print 14 if (x-1)%8==0 and x%2 and solve(x-8) else 8