from math import isqrt N = int(input()) ans = N - 1 for i in range(2, isqrt(N)): if N % i: continue div = N // i for x in range(1, 50): # bisect l, r = 1, div while r - l > 1: m = (r + l) // 2 if (m ** x - 1) < div * (m - 1): l = m else: r = m if (r ** x - 1) == div * (r - 1): ans = min(ans, r) print(ans)