import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;



public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	
	static class Pair
	{
		int x;
		int y;
		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
		
	    @Override
	    public int hashCode() {
	        return (this.x ^ this.y);
	    }

	    @Override
	    public boolean equals(Object obj) {
	        if (this == obj)
	            return true;
	        if (obj == null)
	            return false;
	        if (getClass() != obj.getClass())
	            return false;
	        Pair other = (Pair) obj;
	        if (x != other.x)
	            return false;
	        if (y != other.y)
	            return false;
	        return true;
	    }
	    
	    static class Compare { 
			  
		    static void compare(Pair arr[]) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } 
		}
	}
	
	static class Edge
	{
		int x;
		int y;
		Edge(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
	}
	
	static class Compare { 
		  
	    void compare(Pair arr[]) 
	    { 
	        // Comparator to sort the pair according to second element 
	        Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }); 
	  
	       
	    } 
	} 
	public static long gcd(long a,long b)  
	{  
	    if (a == 0)  
	        return b;  
	    return gcd(b%a, a);  
	}  
	  

	
	
	
	public static long power(long x,long y,long m)  
    { 
        if (y == 0) 
            return 1; 
          
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; 
    }
	
	
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        long h = sc.nextLong();
       
        int x = (int) ((double)Math.log(h)/Math.log(2));
        
        int n = x+1;
        
        long num = (long)Math.pow(2,n)-1;
        out.println(num);
        out.close();
	}

} Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        } @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } compare { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x; p1.y != p2.y p1.y p1 p1.y p2.y p2 p2.y return p1.y - p2.y; p1.y - p2.y p1.y p1 p1.y p2.y p2 p2.y return p2.x-p1.x; p2.x-p1.x p2.x p2 p2.x p1.x p1 p1.x Pair p1 p1 Pair p2 p2 Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        } @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } compare { 	
	                return p1.y - p2.y;
	            } return p1.y - p2.y; p1.y - p2.y p1.y p1 p1.y p2.y p2 p2.y Pair p1 p1 Pair p2 p2 import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.OutputStream; OutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.Iterator; Iterator java.util import java.util.LinkedList; LinkedList java.util import java.util.PriorityQueue; PriorityQueue java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	
	static class Pair
	{
		int x;
		int y;
		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
		
	    @Override
	    public int hashCode() {
	        return (this.x ^ this.y);
	    }

	    @Override
	    public boolean equals(Object obj) {
	        if (this == obj)
	            return true;
	        if (obj == null)
	            return false;
	        if (getClass() != obj.getClass())
	            return false;
	        Pair other = (Pair) obj;
	        if (x != other.x)
	            return false;
	        if (y != other.y)
	            return false;
	        return true;
	    }
	    
	    static class Compare { 
			  
		    static void compare(Pair arr[]) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } 
		}
	}
	
	static class Edge
	{
		int x;
		int y;
		Edge(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
	}
	
	static class Compare { 
		  
	    void compare(Pair arr[]) 
	    { 
	        // Comparator to sort the pair according to second element 
	        Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }); 
	  
	       
	    } 
	} 
	public static long gcd(long a,long b)  
	{  
	    if (a == 0)  
	        return b;  
	    return gcd(b%a, a);  
	}  
	  

	
	
	
	public static long power(long x,long y,long m)  
    { 
        if (y == 0) 
            return 1; 
          
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; 
    }
	
	
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        long h = sc.nextLong();
       
        int x = (int) ((double)Math.log(h)/Math.log(2));
        
        int n = x+1;
        
        long num = (long)Math.pow(2,n)-1;
        out.println(num);
        out.close();
	}

} Main public static long gcd(long a,long b)  
	{  
	    if (a == 0)  
	        return b;  
	    return gcd(b%a, a);  
	} gcd {  
	    if (a == 0)  
	        return b;  
	    return gcd(b%a, a);  
	} if (a == 0)  
	        return b; a == 0 a 0 return b; b return gcd(b%a, a); gcd(b%a, a) gcd b%a b a a long a a long b b public static long power(long x,long y,long m)  
    { 
        if (y == 0) 
            return 1; 
          
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; 
    } power { 
        if (y == 0) 
            return 1; 
          
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; 
    } if (y == 0) 
            return 1; y == 0 y 0 return 1; 1 long p = power(x, y / 2, m) % m; p power(x, y / 2, m) % m power(x, y / 2, m) power x y / 2 y 2 m m p = (p * p) % m p (p * p) % m (p * p) p p m if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; y % 2 == 0 y % 2 y 2 0 return p; p return (x * p) % m; (x * p) % m (x * p) x p m long x x long y y long m m public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        long h = sc.nextLong();
       
        int x = (int) ((double)Math.log(h)/Math.log(2));
        
        int n = x+1;
        
        long num = (long)Math.pow(2,n)-1;
        out.println(num);
        out.close();
	} main {
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        long h = sc.nextLong();
       
        int x = (int) ((double)Math.log(h)/Math.log(2));
        
        int n = x+1;
        
        long num = (long)Math.pow(2,n)-1;
        out.println(num);
        out.close();
	} OutputStream outputStream = System.out; outputStream System.out System System.out FastReader sc = new FastReader(); sc new FastReader() PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc int x = (int) ((double)Math.log(h)/Math.log(2)); x (int) ((double)Math.log(h)/Math.log(2)) (double)Math.log(h) Math.log Math h Math.log(2) Math.log Math 2 int n = x+1; n x+1 x 1 long num = (long)Math.pow(2,n)-1; num (long)Math.pow(2,n)-1 (long)Math.pow(2,n) Math.pow Math 2 n 1 out.println(num) out.println out num out.close() out.close out String[] args args static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } FastReader BufferedReader br; br StringTokenizer st; st public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } FastReader { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } br = new BufferedReader(new
                     InputStreamReader(System.in)) br new BufferedReader(new
                     InputStreamReader(System.in)) String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } next { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } IOException  e { 
                    e.printStackTrace(); 
                } e.printStackTrace() e.printStackTrace e { 
                    st = new StringTokenizer(br.readLine()); 
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } nextInt { 
            return Integer.parseInt(next()); 
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() 
        { 
            return Long.parseLong(next()); 
        } nextLong { 
            return Long.parseLong(next()); 
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } nextDouble { 
            return Double.parseDouble(next()); 
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } nextLine { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } String str = ""; str "" try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } catch (IOException e) 
            { 
                e.printStackTrace(); 
            } IOException e { 
                e.printStackTrace(); 
            } e.printStackTrace() e.printStackTrace e { 
                str = br.readLine(); 
            } str = br.readLine() str br.readLine() br.readLine br return str; str static class Pair
	{
		int x;
		int y;
		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
		
	    @Override
	    public int hashCode() {
	        return (this.x ^ this.y);
	    }

	    @Override
	    public boolean equals(Object obj) {
	        if (this == obj)
	            return true;
	        if (obj == null)
	            return false;
	        if (getClass() != obj.getClass())
	            return false;
	        Pair other = (Pair) obj;
	        if (x != other.x)
	            return false;
	        if (y != other.y)
	            return false;
	        return true;
	    }
	    
	    static class Compare { 
			  
		    static void compare(Pair arr[]) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } 
		}
	} Pair int x; x int y; y Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		} Pair {
			this.x = x;
			this.y = y;
		} this.x = x this.x this this.x x this.y = y this.y this this.y y int x x int y y @Override
	    public int hashCode() {
	        return (this.x ^ this.y);
	    } hashCode {
	        return (this.x ^ this.y);
	    } return (this.x ^ this.y); (this.x ^ this.y) this.x this this.x this.y this this.y @Override
	    public boolean equals(Object obj) {
	        if (this == obj)
	            return true;
	        if (obj == null)
	            return false;
	        if (getClass() != obj.getClass())
	            return false;
	        Pair other = (Pair) obj;
	        if (x != other.x)
	            return false;
	        if (y != other.y)
	            return false;
	        return true;
	    } equals {
	        if (this == obj)
	            return true;
	        if (obj == null)
	            return false;
	        if (getClass() != obj.getClass())
	            return false;
	        Pair other = (Pair) obj;
	        if (x != other.x)
	            return false;
	        if (y != other.y)
	            return false;
	        return true;
	    } if (this == obj)
	            return true; this == obj this obj return true; true if (obj == null)
	            return false; obj == null obj null return false; false if (getClass() != obj.getClass())
	            return false; getClass() != obj.getClass() getClass() getClass obj.getClass() obj.getClass obj return false; false Pair other = (Pair) obj; other (Pair) obj if (x != other.x)
	            return false; x != other.x x other.x other other.x return false; false if (y != other.y)
	            return false; y != other.y y other.y other other.y return false; false return true; true Object obj obj static class Compare { 
			  
		    static void compare(Pair arr[]) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } 
		} Compare static void compare(Pair arr[]) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } compare { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }) Arrays.sort Arrays arr new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        } Pair arr[] arr static class Edge
	{
		int x;
		int y;
		Edge(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
	} Edge int x; x int y; y Edge(int x,int y)
		{
			this.x = x;
			this.y = y;
		} Edge {
			this.x = x;
			this.y = y;
		} this.x = x this.x this this.x x this.y = y this.y this this.y y int x x int y y static class Compare { 
		  
	    void compare(Pair arr[]) 
	    { 
	        // Comparator to sort the pair according to second element 
	        Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }); 
	  
	       
	    } 
	} Compare void compare(Pair arr[]) 
	    { 
	        // Comparator to sort the pair according to second element 
	        Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }); 
	  
	       
	    } compare { 
	        // Comparator to sort the pair according to second element 
	        Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }); 
	  
	       
	    } Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }) Arrays.sort Arrays arr new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        } Pair arr[] arr public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	
	static class Pair
	{
		int x;
		int y;
		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
		
	    @Override
	    public int hashCode() {
	        return (this.x ^ this.y);
	    }

	    @Override
	    public boolean equals(Object obj) {
	        if (this == obj)
	            return true;
	        if (obj == null)
	            return false;
	        if (getClass() != obj.getClass())
	            return false;
	        Pair other = (Pair) obj;
	        if (x != other.x)
	            return false;
	        if (y != other.y)
	            return false;
	        return true;
	    }
	    
	    static class Compare { 
			  
		    static void compare(Pair arr[]) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } 
		}
	}
	
	static class Edge
	{
		int x;
		int y;
		Edge(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
	}
	
	static class Compare { 
		  
	    void compare(Pair arr[]) 
	    { 
	        // Comparator to sort the pair according to second element 
	        Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }); 
	  
	       
	    } 
	} 
	public static long gcd(long a,long b)  
	{  
	    if (a == 0)  
	        return b;  
	    return gcd(b%a, a);  
	}  
	  

	
	
	
	public static long power(long x,long y,long m)  
    { 
        if (y == 0) 
            return 1; 
          
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; 
    }
	
	
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        long h = sc.nextLong();
       
        int x = (int) ((double)Math.log(h)/Math.log(2));
        
        int n = x+1;
        
        long num = (long)Math.pow(2,n)-1;
        out.println(num);
        out.close();
	}

} public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	
	static class Pair
	{
		int x;
		int y;
		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
		
	    @Override
	    public int hashCode() {
	        return (this.x ^ this.y);
	    }

	    @Override
	    public boolean equals(Object obj) {
	        if (this == obj)
	            return true;
	        if (obj == null)
	            return false;
	        if (getClass() != obj.getClass())
	            return false;
	        Pair other = (Pair) obj;
	        if (x != other.x)
	            return false;
	        if (y != other.y)
	            return false;
	        return true;
	    }
	    
	    static class Compare { 
			  
		    static void compare(Pair arr[]) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } 
		}
	}
	
	static class Edge
	{
		int x;
		int y;
		Edge(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
	}
	
	static class Compare { 
		  
	    void compare(Pair arr[]) 
	    { 
	        // Comparator to sort the pair according to second element 
	        Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }); 
	  
	       
	    } 
	} 
	public static long gcd(long a,long b)  
	{  
	    if (a == 0)  
	        return b;  
	    return gcd(b%a, a);  
	}  
	  

	
	
	
	public static long power(long x,long y,long m)  
    { 
        if (y == 0) 
            return 1; 
          
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; 
    }
	
	
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        long h = sc.nextLong();
       
        int x = (int) ((double)Math.log(h)/Math.log(2));
        
        int n = x+1;
        
        long num = (long)Math.pow(2,n)-1;
        out.println(num);
        out.close();
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;



public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	
	static class Pair
	{
		int x;
		int y;
		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
		
	    @Override
	    public int hashCode() {
	        return (this.x ^ this.y);
	    }

	    @Override
	    public boolean equals(Object obj) {
	        if (this == obj)
	            return true;
	        if (obj == null)
	            return false;
	        if (getClass() != obj.getClass())
	            return false;
	        Pair other = (Pair) obj;
	        if (x != other.x)
	            return false;
	        if (y != other.y)
	            return false;
	        return true;
	    }
	    
	    static class Compare { 
			  
		    static void compare(Pair arr[]) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 	
		            	if(p1.y != p2.y)
		                return p1.y - p2.y; 
		            	
		            	else
		            	return p2.x-p1.x;
		            } 
		        }); 
		  
		       
		    } 
		}
	}
	
	static class Edge
	{
		int x;
		int y;
		Edge(int x,int y)
		{
			this.x = x;
			this.y = y;
		}
	}
	
	static class Compare { 
		  
	    void compare(Pair arr[]) 
	    { 
	        // Comparator to sort the pair according to second element 
	        Arrays.sort(arr, new Comparator<Pair>() { 
	            @Override public int compare(Pair p1, Pair p2) 
	            { 	
	                return p1.y - p2.y;
	            } 
	        }); 
	  
	       
	    } 
	} 
	public static long gcd(long a,long b)  
	{  
	    if (a == 0)  
	        return b;  
	    return gcd(b%a, a);  
	}  
	  

	
	
	
	public static long power(long x,long y,long m)  
    { 
        if (y == 0) 
            return 1; 
          
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; 
    }
	
	
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        long h = sc.nextLong();
       
        int x = (int) ((double)Math.log(h)/Math.log(2));
        
        int n = x+1;
        
        long num = (long)Math.pow(2,n)-1;
        out.println(num);
        out.close();
	}

}
