import sys import math N=input() isok=[0]*100 vis=[0]*100 for i in range(2,100): for j in range(2,i): if i%j==0: isok[i]=1 def ok(N,M): q=[1] while len(q) > 0: v = q[-1] q.pop() for t in (v-1,v+1,v-M,v+M): if v%M==1 and t==v-1: continue if v%M==0 and t==v+1: continue if t<=0 or t>N: continue if isok[t] and vis[t]=50: print 8 else: for M in range(2,50): if ok(N,M): print M break