N = int(input()) #約数の後半列挙 def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i < n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return upper_divisors[::-1] #めぐる式二部探索 #参考サイト:https://aotamasaki.hatenablog.com/entry/meguru_bisect def is_ok(arg,tar,n): # 整数を買えればTrueを返す return (arg**n-1)//(arg-1) <= tar def meguru_bisect(ng, ok, tar, n): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid,tar,n): ok = mid else: ng = mid return ok L=make_divisors(N) ans = N-1 for l in L: for i in range(2,40): temp = meguru_bisect(N + 1, 1 ,l ,i) if temp>1 and (temp**i)//(temp-1)==l: ans = min(temp,ans) print(ans)