import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long t = 1;
        long ret = t;
        for(int i=0;Math.pow(2,i+1)<=h;i++){
          t *= 2;
          ret += t;
        }

        System.out.println(ret);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long t = 1;
        long ret = t;
        for(int i=0;Math.pow(2,i+1)<=h;i++){
          t *= 2;
          ret += t;
        }

        System.out.println(ret);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long t = 1;
        long ret = t;
        for(int i=0;Math.pow(2,i+1)<=h;i++){
          t *= 2;
          ret += t;
        }

        System.out.println(ret);
    } main {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long t = 1;
        long ret = t;
        for(int i=0;Math.pow(2,i+1)<=h;i++){
          t *= 2;
          ret += t;
        }

        System.out.println(ret);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long t = 1; t 1 long ret = t; ret t for(int i=0;Math.pow(2,i+1)<=h;i++){
          t *= 2;
          ret += t;
        } int i=0; int i=0; i 0 Math.pow(2,i+1)<=h Math.pow(2,i+1) Math.pow Math 2 i+1 i 1 h i++ i++ i {
          t *= 2;
          ret += t;
        } {
          t *= 2;
          ret += t;
        } t *= 2 t 2 ret += t ret t System.out.println(ret) System.out.println System.out System System.out ret 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 t = 1;
        long ret = t;
        for(int i=0;Math.pow(2,i+1)<=h;i++){
          t *= 2;
          ret += t;
        }

        System.out.println(ret);
    }
}