import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N = int(input()) cnt = 2 while True: base = N lis = [] while base>0: if lis and base%cnt!=lis[-1]: break lis.append(base%cnt) base //= cnt if base==0: print(cnt) exit() cnt += 1