N = int(input()) for p in range(2, 10 ** 6 + 10): s = 0 a = 1 f = 0 while s < N: s += a a *= p if N % s == 0 and N // s < p: f = 1 break if f: print(p) break else: print(N - 1)