import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long h = sc.nextLong();

		int n = 0;
		double hp = 1;
		for(int i=0;i<100;i++) {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		}

		long ans = 0;
		for(int i=0;i<n;i++) {
			double add = Math.pow(2, i);
			ans += (long)add;
		}

		System.out.println(ans);

	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long h = sc.nextLong();

		int n = 0;
		double hp = 1;
		for(int i=0;i<100;i++) {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		}

		long ans = 0;
		for(int i=0;i<n;i++) {
			double add = Math.pow(2, i);
			ans += (long)add;
		}

		System.out.println(ans);

	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long h = sc.nextLong();

		int n = 0;
		double hp = 1;
		for(int i=0;i<100;i++) {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		}

		long ans = 0;
		for(int i=0;i<n;i++) {
			double add = Math.pow(2, i);
			ans += (long)add;
		}

		System.out.println(ans);

	} main {

		Scanner sc = new Scanner(System.in);

		long h = sc.nextLong();

		int n = 0;
		double hp = 1;
		for(int i=0;i<100;i++) {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		}

		long ans = 0;
		for(int i=0;i<n;i++) {
			double add = Math.pow(2, i);
			ans += (long)add;
		}

		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 int n = 0; n 0 double hp = 1; hp 1 for(int i=0;i<100;i++) {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		} int i=0; int i=0; i 0 i<100 i 100 i++ i++ i {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		} {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		} if(i!=0) {
				hp *= 2;
			} i!=0 i 0 {
				hp *= 2;
			} hp *= 2 hp 2 if(h<hp) {
				n=i;
				break;
			} h<hp h hp {
				n=i;
				break;
			} n=i n i break; long ans = 0; ans 0 for(int i=0;i<n;i++) {
			double add = Math.pow(2, i);
			ans += (long)add;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			double add = Math.pow(2, i);
			ans += (long)add;
		} {
			double add = Math.pow(2, i);
			ans += (long)add;
		} double add = Math.pow(2, i); add Math.pow(2, i) Math.pow Math 2 i ans += (long)add ans (long)add 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();

		int n = 0;
		double hp = 1;
		for(int i=0;i<100;i++) {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		}

		long ans = 0;
		for(int i=0;i<n;i++) {
			double add = Math.pow(2, i);
			ans += (long)add;
		}

		System.out.println(ans);

	}
} public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long h = sc.nextLong();

		int n = 0;
		double hp = 1;
		for(int i=0;i<100;i++) {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		}

		long ans = 0;
		for(int i=0;i<n;i++) {
			double add = Math.pow(2, i);
			ans += (long)add;
		}

		System.out.println(ans);

	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long h = sc.nextLong();

		int n = 0;
		double hp = 1;
		for(int i=0;i<100;i++) {
			if(i!=0) {
				hp *= 2;
			}
			if(h<hp) {
				n=i;
				break;
			}
		}

		long ans = 0;
		for(int i=0;i<n;i++) {
			double add = Math.pow(2, i);
			ans += (long)add;
		}

		System.out.println(ans);

	}
}
