# さっきのACは嘘解法 # Nの約数-1だけでなく、(Nの約数-1)の約数もpの候補 def base_k(num, k): result = set() while num > 0: amari = num%k result.add(amari) num -= amari num //= k return len(result) 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()) divs = divisors(N) divs_divs = set() for d in divs: for d2 in divisors(d-1): if d2 > 1: divs_divs.add(d2) divs_divs_sorted = sorted(list(divs_divs)) #print(divs_divs_sorted) for d3 in divs_divs_sorted: if d3 == 1: continue calc = base_k(N, d3) if calc == 1: print(d3) exit()