import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); long d = sc.nextLong(); long left = 0; long right = d; while (right - left > 1) { long m = (left + right) / 2; long x = m; long sum = 0; while (x > 0) { sum += x; x /= 2; } if (sum >= d) { right = m; } else { left = m; } } for (long i = right; i <= d; i++) { long x = i; long sum = 0; while (x > 0 && sum < d) { sum += x; x /= 2; } if (sum == d) { System.out.println(i); return; } } } }