import java.util.*; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long n = scan.nextLong(); int k = Long.bitCount(n); System.out.println(n + 1 - (1L << k)); } }