import java.io.*; import java.math.*; import java.util.*; public class Main { static int[] vy = {1,0,-1,0}; static int[] vx = {0,1,0,-1}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); long in = sc.nextLong(); long sum = 0; long max = 0; while(in != 0) { max = Math.max(max, sum + in*2); sum += in; in /= 2; } System.out.println(max - sum); } }