d=int(input()) def distance(x): res=0 while x>0: res+=x x//=2 if res>=d: break return res for i in range(100,0,-1): t=d*(2**(i-1))//(2**i-1) for j in range(-50,50): if t+j<0: continue if distance(t+j)==d: print(t+j) exit()