n=gets.to_i k=i=s=0 while s=n p ('1'*(i+1)+'0'*(s+k-i-n-1)+'1'*(-s+n)).to_i(2);exit else s+=k-2-i+=1 end end p 2**k-1