n = int(input()) ans = n - 1 if n > 2 else n + 1 for i in range(2, int(n ** 0.5 + 9)): sm = 0 while sm <= n: sm = sm * i + 1 if n % sm == 0 and n // sm < i: ans = min(ans, i) if n % i == 0 and i < n // i - 1: ans = min(ans, n // i - 1) print(ans)