#395 17 forever import math N=int(input()) if N<15: print(-1) else: i=8 nd=0 while nd==0 and i<=math.sqrt(N): if N%i==0: nd=i i+=1 if nd>0: print(nd) else: print(N-7)