import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long h = in.nextLong();
        long[] dp = new long[1000];
        //initialize
        for(int i = 0; i < 1000; i++) {
            dp[i] = -1;
        }
        dp[0] = 0;
        dp[1] = 1;
        
        System.out.println(solve(h));
        
    }

    public static long solve(long x) {
        if(x == 1) {
            return 1;
        } else {
            return 2 * solve(x/2) + 1;
        }
    }

} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long h = in.nextLong();
        long[] dp = new long[1000];
        //initialize
        for(int i = 0; i < 1000; i++) {
            dp[i] = -1;
        }
        dp[0] = 0;
        dp[1] = 1;
        
        System.out.println(solve(h));
        
    }

    public static long solve(long x) {
        if(x == 1) {
            return 1;
        } else {
            return 2 * solve(x/2) + 1;
        }
    }

} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long h = in.nextLong();
        long[] dp = new long[1000];
        //initialize
        for(int i = 0; i < 1000; i++) {
            dp[i] = -1;
        }
        dp[0] = 0;
        dp[1] = 1;
        
        System.out.println(solve(h));
        
    } main {
        Scanner in = new Scanner(System.in);
        long h = in.nextLong();
        long[] dp = new long[1000];
        //initialize
        for(int i = 0; i < 1000; i++) {
            dp[i] = -1;
        }
        dp[0] = 0;
        dp[1] = 1;
        
        System.out.println(solve(h));
        
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) long h = in.nextLong(); h in.nextLong() in.nextLong in long[] dp = new long[1000]; dp new long[1000] 1000 for(int i = 0; i < 1000; i++) {
            dp[i] = -1;
        } int i = 0; int i = 0; i 0 i < 1000 i 1000 i++ i++ i {
            dp[i] = -1;
        } {
            dp[i] = -1;
        } dp[i] = -1 dp[i] dp i -1 1 dp[0] = 0 dp[0] dp 0 0 dp[1] = 1 dp[1] dp 1 1 System.out.println(solve(h)) System.out.println System.out System System.out solve(h) solve h String[] args args public static long solve(long x) {
        if(x == 1) {
            return 1;
        } else {
            return 2 * solve(x/2) + 1;
        }
    } solve {
        if(x == 1) {
            return 1;
        } else {
            return 2 * solve(x/2) + 1;
        }
    } if(x == 1) {
            return 1;
        } else {
            return 2 * solve(x/2) + 1;
        } x == 1 x 1 {
            return 1;
        } return 1; 1 {
            return 2 * solve(x/2) + 1;
        } return 2 * solve(x/2) + 1; 2 * solve(x/2) + 1 2 * solve(x/2) 2 solve(x/2) solve x/2 x 2 1 long x x public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long h = in.nextLong();
        long[] dp = new long[1000];
        //initialize
        for(int i = 0; i < 1000; i++) {
            dp[i] = -1;
        }
        dp[0] = 0;
        dp[1] = 1;
        
        System.out.println(solve(h));
        
    }

    public static long solve(long x) {
        if(x == 1) {
            return 1;
        } else {
            return 2 * solve(x/2) + 1;
        }
    }

} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long h = in.nextLong();
        long[] dp = new long[1000];
        //initialize
        for(int i = 0; i < 1000; i++) {
            dp[i] = -1;
        }
        dp[0] = 0;
        dp[1] = 1;
        
        System.out.println(solve(h));
        
    }

    public static long solve(long x) {
        if(x == 1) {
            return 1;
        } else {
            return 2 * solve(x/2) + 1;
        }
    }

} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long h = in.nextLong();
        long[] dp = new long[1000];
        //initialize
        for(int i = 0; i < 1000; i++) {
            dp[i] = -1;
        }
        dp[0] = 0;
        dp[1] = 1;
        
        System.out.println(solve(h));
        
    }

    public static long solve(long x) {
        if(x == 1) {
            return 1;
        } else {
            return 2 * solve(x/2) + 1;
        }
    }

}
