import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		System.out.println(saiki(h));
	}
	public static long saiki(long h){
		if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		}
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		System.out.println(saiki(h));
	}
	public static long saiki(long h){
		if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		System.out.println(saiki(h));
	} main {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		System.out.println(saiki(h));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc System.out.println(saiki(h)) System.out.println System.out System System.out saiki(h) saiki h String[] args args public static long saiki(long h){
		if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		}
	} saiki {
		if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		}
	} if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		} h==1 h 1 return 1; 1 {
			return 2*saiki(h/2)+1;
		} return 2*saiki(h/2)+1; 2*saiki(h/2)+1 2*saiki(h/2) 2 saiki(h/2) saiki h/2 h 2 1 long h h public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		System.out.println(saiki(h));
	}
	public static long saiki(long h){
		if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		System.out.println(saiki(h));
	}
	public static long saiki(long h){
		if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		}
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		System.out.println(saiki(h));
	}
	public static long saiki(long h){
		if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		}
	}
}
