import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long t = 1;
		long ans = 0;
		
		while (H >= t) {
			ans += t;
			t *= 2;
		}
		System.out.println(ans);
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long t = 1;
		long ans = 0;
		
		while (H >= t) {
			ans += t;
			t *= 2;
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long t = 1;
		long ans = 0;
		
		while (H >= t) {
			ans += t;
			t *= 2;
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long t = 1;
		long ans = 0;
		
		while (H >= t) {
			ans += t;
			t *= 2;
		}
		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 t = 1; t 1 long ans = 0; ans 0 while (H >= t) {
			ans += t;
			t *= 2;
		} H >= t H t {
			ans += t;
			t *= 2;
		} ans += t ans t t *= 2 t 2 System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long t = 1;
		long ans = 0;
		
		while (H >= t) {
			ans += t;
			t *= 2;
		}
		System.out.println(ans);
	}
}