import java.util.Arrays;
import java.util.Scanner;
 

public class Main {
 
	
	public static int get(String a[],int index,int k,boolean visited[]) {
		
		if(index==a.length-1) {
			return 0;
		}
		if(index>=a.length || index<0 || visited[index]) {
			return Integer.MAX_VALUE/2;
		}
		
		visited[index] = true;
		int min = Integer.MAX_VALUE/2;
		for(int i=index+1;i<=index+k && i<a.length;i++) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		for(int i=index-1;i>=index-k && i>=0;i--) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		
		return min;
	}
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		
			long h = s.nextLong();
			long ctr=1,sum=0;
			while(h>0) {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			}
			System.out.println(sum);
		
	    
		
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
 
	
	public static int get(String a[],int index,int k,boolean visited[]) {
		
		if(index==a.length-1) {
			return 0;
		}
		if(index>=a.length || index<0 || visited[index]) {
			return Integer.MAX_VALUE/2;
		}
		
		visited[index] = true;
		int min = Integer.MAX_VALUE/2;
		for(int i=index+1;i<=index+k && i<a.length;i++) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		for(int i=index-1;i>=index-k && i>=0;i--) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		
		return min;
	}
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		
			long h = s.nextLong();
			long ctr=1,sum=0;
			while(h>0) {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			}
			System.out.println(sum);
		
	    
		
	}
} Main public static int get(String a[],int index,int k,boolean visited[]) {
		
		if(index==a.length-1) {
			return 0;
		}
		if(index>=a.length || index<0 || visited[index]) {
			return Integer.MAX_VALUE/2;
		}
		
		visited[index] = true;
		int min = Integer.MAX_VALUE/2;
		for(int i=index+1;i<=index+k && i<a.length;i++) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		for(int i=index-1;i>=index-k && i>=0;i--) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		
		return min;
	} get {
		
		if(index==a.length-1) {
			return 0;
		}
		if(index>=a.length || index<0 || visited[index]) {
			return Integer.MAX_VALUE/2;
		}
		
		visited[index] = true;
		int min = Integer.MAX_VALUE/2;
		for(int i=index+1;i<=index+k && i<a.length;i++) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		for(int i=index-1;i>=index-k && i>=0;i--) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		
		return min;
	} if(index==a.length-1) {
			return 0;
		} index==a.length-1 index a.length-1 a.length a a.length 1 {
			return 0;
		} return 0; 0 if(index>=a.length || index<0 || visited[index]) {
			return Integer.MAX_VALUE/2;
		} index>=a.length || index<0 || visited[index] index>=a.length || index<0 || visited[index] index>=a.length index a.length a a.length index<0 index 0 visited[index] visited index {
			return Integer.MAX_VALUE/2;
		} return Integer.MAX_VALUE/2; Integer.MAX_VALUE/2 Integer.MAX_VALUE Integer Integer.MAX_VALUE 2 visited[index] = true visited[index] visited index true int min = Integer.MAX_VALUE/2; min Integer.MAX_VALUE/2 Integer.MAX_VALUE Integer Integer.MAX_VALUE 2 for(int i=index+1;i<=index+k && i<a.length;i++) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		} int i=index+1; int i=index+1; i index+1 index 1 i<=index+k && i<a.length i<=index+k i index+k index k i<a.length i a.length a a.length i++ i++ i {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		} {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		} if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			} a[index].charAt(i)=='1' a[index].charAt(i) a[index].charAt a[index] a index i '1' {
				min = Math.min(min, get(a,i,k,visited)+1);
			} min = Math.min(min, get(a,i,k,visited)+1) min Math.min(min, get(a,i,k,visited)+1) Math.min Math min get(a,i,k,visited)+1 get(a,i,k,visited) get a i k visited 1 for(int i=index-1;i>=index-k && i>=0;i--) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		} int i=index-1; int i=index-1; i index-1 index 1 i>=index-k && i>=0 i>=index-k i index-k index k i>=0 i 0 i-- i-- i {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		} {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		} if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			} a[index].charAt(i)=='1' a[index].charAt(i) a[index].charAt a[index] a index i '1' {
				min = Math.min(min, get(a,i,k,visited)+1);
			} min = Math.min(min, get(a,i,k,visited)+1) min Math.min(min, get(a,i,k,visited)+1) Math.min Math min get(a,i,k,visited)+1 get(a,i,k,visited) get a i k visited 1 return min; min String a[] a int index index int k k boolean visited[] visited public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		
			long h = s.nextLong();
			long ctr=1,sum=0;
			while(h>0) {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			}
			System.out.println(sum);
		
	    
		
	} main {
		
		Scanner s = new Scanner(System.in);
		
			long h = s.nextLong();
			long ctr=1,sum=0;
			while(h>0) {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			}
			System.out.println(sum);
		
	    
		
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) long h = s.nextLong(); h s.nextLong() s.nextLong s long ctr=1 ctr 1 sum=0; sum 0 while(h>0) {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			} h>0 h 0 {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			} sum+=ctr sum ctr ctr*=2 ctr 2 h=h/2 h h/2 h 2 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
 
	
	public static int get(String a[],int index,int k,boolean visited[]) {
		
		if(index==a.length-1) {
			return 0;
		}
		if(index>=a.length || index<0 || visited[index]) {
			return Integer.MAX_VALUE/2;
		}
		
		visited[index] = true;
		int min = Integer.MAX_VALUE/2;
		for(int i=index+1;i<=index+k && i<a.length;i++) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		for(int i=index-1;i>=index-k && i>=0;i--) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		
		return min;
	}
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		
			long h = s.nextLong();
			long ctr=1,sum=0;
			while(h>0) {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			}
			System.out.println(sum);
		
	    
		
	}
} public class Main {
 
	
	public static int get(String a[],int index,int k,boolean visited[]) {
		
		if(index==a.length-1) {
			return 0;
		}
		if(index>=a.length || index<0 || visited[index]) {
			return Integer.MAX_VALUE/2;
		}
		
		visited[index] = true;
		int min = Integer.MAX_VALUE/2;
		for(int i=index+1;i<=index+k && i<a.length;i++) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		for(int i=index-1;i>=index-k && i>=0;i--) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		
		return min;
	}
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		
			long h = s.nextLong();
			long ctr=1,sum=0;
			while(h>0) {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			}
			System.out.println(sum);
		
	    
		
	}
} Main
import java.util.Arrays;
import java.util.Scanner;
 

public class Main {
 
	
	public static int get(String a[],int index,int k,boolean visited[]) {
		
		if(index==a.length-1) {
			return 0;
		}
		if(index>=a.length || index<0 || visited[index]) {
			return Integer.MAX_VALUE/2;
		}
		
		visited[index] = true;
		int min = Integer.MAX_VALUE/2;
		for(int i=index+1;i<=index+k && i<a.length;i++) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		for(int i=index-1;i>=index-k && i>=0;i--) {
			if(a[index].charAt(i)=='1') {
				min = Math.min(min, get(a,i,k,visited)+1);
			}
		}
		
		return min;
	}
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		
			long h = s.nextLong();
			long ctr=1,sum=0;
			while(h>0) {
				sum+=ctr;
				ctr*=2;
				h=h/2;
			}
			System.out.println(sum);
		
	    
		
	}
}