def f(n,p): res=[] while(n>0): res.append(n%p) n//=p return res N=int(input()) p=2 while(True): X=f(N,p) if min(X)==max(X): print(p) exit() p+=1