D = gets.to_i def f(x) len = 0 while x > 0 len += x x /= 2 end len end ng = 0 ok = 10 ** 18 while (ok - ng).abs >= 2 x = (ok + ng) / 2 if D <= f(x) ok = x else ng = x end end if f(ok) != D puts D else puts ok end