import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long ans = 0;
		long buf = 0;
		while(H > 0){
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		}
		System.out.println(ans);
	}
} import java.util.*; util.* java public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long ans = 0;
		long buf = 0;
		while(H > 0){
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		}
		System.out.println(ans);
	}
} Main public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long ans = 0;
		long buf = 0;
		while(H > 0){
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long ans = 0;
		long buf = 0;
		while(H > 0){
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		}
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc long ans = 0; ans 0 long buf = 0; buf 0 while(H > 0){
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		} H > 0 H 0 {
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		} H /= 2 H 2 ans += Math.pow(2,buf) ans Math.pow(2,buf) Math.pow Math 2 buf buf++ buf System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long ans = 0;
		long buf = 0;
		while(H > 0){
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		}
		System.out.println(ans);
	}
} public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long ans = 0;
		long buf = 0;
		while(H > 0){
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		}
		System.out.println(ans);
	}
} Main
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long ans = 0;
		long buf = 0;
		while(H > 0){
			H /= 2;
			ans += Math.pow(2,buf);
			buf++;
		}
		System.out.println(ans);
	}
}