N=int(input()) S=sorted(set([max([(0,i)[i%j==0] for j in range(2,i)]) for i in range(N-100,N+101)])) print(S[1])