import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } static long[][] c = new long[10][10]; { c[0][0] = 1; for (int i = 1; i < 10; ++i) { for (int j = 0; j <= i; ++j) { c[i][j] = c[i - 1][j] + (j > 0 ? c[i - 1][j - 1] : 0); // if (c[i][j] % 2 == 0) { // System.out.println(Integer.toBinaryString(i)); // System.out.println(Integer.toBinaryString(j)); // System.out.println(); // } } } } static void run() { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); int[] cnt = new int[2]; long d = n; while (d > 0) { ++cnt[(int) d % 2]; d /= 2; } System.out.println((n + 1) - (1L << cnt[1])); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }