N = int(input()) def divisor(n): cd = [] i = 1 while i*i <= n: if n%i==0: # cd.append(i) if n//i - i >= 2: cd.append(n//i) i += 1 return cd[-1] ans = divisor(N)-1 for m in range(3,41): p = 2 while pow(p,m)-1<=N*(p-1): if (N*(p-1))%(pow(p,m)-1)==0: ans = min(ans, p) break p += 1 print(ans)