import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long total = 0;
		int count = 0;
		if(h == 1) {
			System.out.println(1);
			return;
		}
		while(h > 0) {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		}
		if(h % 2 == 1) {
			System.out.println(total + 2);
		}else {
			System.out.println(total);
		}

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long total = 0;
		int count = 0;
		if(h == 1) {
			System.out.println(1);
			return;
		}
		while(h > 0) {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		}
		if(h % 2 == 1) {
			System.out.println(total + 2);
		}else {
			System.out.println(total);
		}

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long total = 0;
		int count = 0;
		if(h == 1) {
			System.out.println(1);
			return;
		}
		while(h > 0) {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		}
		if(h % 2 == 1) {
			System.out.println(total + 2);
		}else {
			System.out.println(total);
		}

	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long total = 0;
		int count = 0;
		if(h == 1) {
			System.out.println(1);
			return;
		}
		while(h > 0) {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		}
		if(h % 2 == 1) {
			System.out.println(total + 2);
		}else {
			System.out.println(total);
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long total = 0; total 0 int count = 0; count 0 if(h == 1) {
			System.out.println(1);
			return;
		} h == 1 h 1 {
			System.out.println(1);
			return;
		} System.out.println(1) System.out.println System.out System System.out 1 return; while(h > 0) {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		} h > 0 h 0 {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		} h /= 2 h 2 total += Math.pow(2,count) total Math.pow(2,count) Math.pow Math 2 count count++ count if(h % 2 == 1) {
			System.out.println(total + 2);
		}else {
			System.out.println(total);
		} h % 2 == 1 h % 2 h 2 1 {
			System.out.println(total + 2);
		} System.out.println(total + 2) System.out.println System.out System System.out total + 2 total 2 {
			System.out.println(total);
		} System.out.println(total) System.out.println System.out System System.out total String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long total = 0;
		int count = 0;
		if(h == 1) {
			System.out.println(1);
			return;
		}
		while(h > 0) {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		}
		if(h % 2 == 1) {
			System.out.println(total + 2);
		}else {
			System.out.println(total);
		}

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long total = 0;
		int count = 0;
		if(h == 1) {
			System.out.println(1);
			return;
		}
		while(h > 0) {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		}
		if(h % 2 == 1) {
			System.out.println(total + 2);
		}else {
			System.out.println(total);
		}

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long total = 0;
		int count = 0;
		if(h == 1) {
			System.out.println(1);
			return;
		}
		while(h > 0) {
			h /= 2;
			total += Math.pow(2,count);
			count++;
		}
		if(h % 2 == 1) {
			System.out.println(total + 2);
		}else {
			System.out.println(total);
		}

	}

}
