def base_k(num, k): result = [] while num > 0: amari = num%k result.append(amari) num -= amari num //= k return result[::-1] def divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] N = int(input()) if N <= 2: print(N+1) exit() for i in range(2, N): calc = base_k(N, i) if len(calc) > 1 and len(set(calc)) == 1: #print(i, calc) print(i) exit() divs = divisors(N) for d in divs: if d <= N: continue calc = base_k(N, d-1) if len(set(calc)) == 1: #print(d-1, calc) print(d-1) exit()