import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0L;
        int count = 0;

        while(true){
            long und = (long)Math.pow(2,count);
            ans += und;

            if(h/und <= 1L)
                break;

            count++;
        }

        System.out.println(ans);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0L;
        int count = 0;

        while(true){
            long und = (long)Math.pow(2,count);
            ans += und;

            if(h/und <= 1L)
                break;

            count++;
        }

        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0L;
        int count = 0;

        while(true){
            long und = (long)Math.pow(2,count);
            ans += und;

            if(h/und <= 1L)
                break;

            count++;
        }

        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0L;
        int count = 0;

        while(true){
            long und = (long)Math.pow(2,count);
            ans += und;

            if(h/und <= 1L)
                break;

            count++;
        }

        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long ans = 0L; ans 0L int count = 0; count 0 while(true){
            long und = (long)Math.pow(2,count);
            ans += und;

            if(h/und <= 1L)
                break;

            count++;
        } true {
            long und = (long)Math.pow(2,count);
            ans += und;

            if(h/und <= 1L)
                break;

            count++;
        } long und = (long)Math.pow(2,count); und (long)Math.pow(2,count) Math.pow Math 2 count ans += und ans und if(h/und <= 1L)
                break; h/und <= 1L h/und h und 1L break; count++ count System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0L;
        int count = 0;

        while(true){
            long und = (long)Math.pow(2,count);
            ans += und;

            if(h/und <= 1L)
                break;

            count++;
        }

        System.out.println(ans);
    }
}