import java.io.*; import java.util.*; public class Main_yukicoder589_1 { private static Scanner sc; private static Printer pr; private static void solve() { long n = sc.nextLong(); pr.println(n + 1 - cntOdd(n)); } private static long cntOdd(long n) { if (n == 0) { return 1; } else if (n == 1) { return 2; } long tmp = 2; while (n >= tmp * 2) { tmp *= 2; } return 2 * cntOdd(n - tmp); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }