import java.util.*; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long n = scan.nextLong(); if (n == 0) { System.out.println(0); } else { long lowestBit = Long.lowestOneBit(n); System.out.println(n / lowestBit * (lowestBit - 1)); } } }