using System; public class Hello { static void Main() { var n = long.Parse(Console.ReadLine().Trim()); getAns(n); } static bool check1(long n, long t) { var sum = t; if (sum == n) { return true; } while (true) { t /= 2; sum += t; if (sum == n) { return true; } if (t == 1) break; } return false; } static bool check0(long n, long t) { var sum = t; while (true) { t /= 2; sum += t; if (t == 1) break; } return sum >= n; } static long getNum(long n) { var ok = n; var ng = 1L; while (ok - ng > 1) { var mid = ng + (ok - ng) / 2; if (check0(n, mid)) ok = mid; else ng = mid; } return ok; } static void getAns(long n) { var c = getNum(n); for (long i = c; i < c + 1000; i++) { if (check1(n, i)) { Console.WriteLine(i); return; } } } }