import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long j = 1;
		long count = 0;
		while(1 <= H) {
			count+= j;
			H /= 2;
			j *= 2;
		}
		System.out.println(count);
	}

} 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();
		long j = 1;
		long count = 0;
		while(1 <= H) {
			count+= j;
			H /= 2;
			j *= 2;
		}
		System.out.println(count);
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long j = 1;
		long count = 0;
		while(1 <= H) {
			count+= j;
			H /= 2;
			j *= 2;
		}
		System.out.println(count);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long j = 1;
		long count = 0;
		while(1 <= H) {
			count+= j;
			H /= 2;
			j *= 2;
		}
		System.out.println(count);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long j = 1;
		long count = 0;
		while(1 <= H) {
			count+= j;
			H /= 2;
			j *= 2;
		}
		System.out.println(count);
	}

}
