import random def solve(n): d=n-1 while d&1==0: d/=2 for l in range(0,100): a=random.randint(1,n-2) t=d y=pow(a,t,n) while t!=n-1 and y!=1 and y!=n-1: y=(y*y)%n t*=2 if y!=n-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