n = int(input()) if n <= 2: print(n + 1) exit() def ok(p): m = n x = m % p m //= p while m > 0: if m % p != x: return False m //= p return True for p in range(2, int(n ** 0.5 + 1)): if ok(p): print(p) exit() print(n - 1)