using static System.Math; using System; public class Hello { static void Main() { var n = long.Parse(Console.ReadLine().Trim()); getAns(n); } static void getAns (long n) { var ans = long.MaxValue; for (int k = 0; k < 65; k++) { var w = BS(n, k); if (w != -1) ans = Min(ans, w); } Console.WriteLine(ans); } static long BS (long targ, int k) { var ng = 1L; var ok = targ; while (ok - ng > 1) { var mid = ng + (ok - ng) / 2; var w = calc(mid, k); if (w == targ) return mid; else if (w > targ) ok = mid; else ng = mid; } return -1; } static long calc (long n , int k) { var res = n; var p = 1; while (p < k && n >0) { n /= 2; res += n; p++; } return res; } }