N=int(input()) for i in range(2,int(N**0.5)): M=N P=[] while M: P.append(M%i) M//=i if len(set(P))==1: print(i) exit() print(N-1)