import sys input = sys.stdin.readline N = int(input()) # 1 ans = N - 1 # 2 i = 2 while i * i <= N: if N % i == 0 and i < N // i - 1: ans = min(ans, N // i - 1) i += 1 # >= 3 p = 2 while p * p <= N: n = N s = set() while n > 0: s.add(n % p) n //= p if len(s) == 1: ans = min(ans, p) p += 1 print(ans)