N = int(input()) def divisor(n): cd = [] i = 1 while i*i <= n: if n%i==0: # cd.append(i) if n//i - i >= 2: cd.append(n//i) i += 1 return cd[-1] if N<=2: print(N+1) exit() ans = divisor(N)-1 for m in range(3,41): p = 2 while pow(p,m)-1<=N*(p-1): b = (pow(p,m)-1)//(p-1) if N%b==0 and N//b