import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long mainsum = clac(h, (long)0);
        System.out.println(mainsum);
    }
    public static long clac(long h,long ret){
        long sum = ret;
        if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        }
        return sum;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long mainsum = clac(h, (long)0);
        System.out.println(mainsum);
    }
    public static long clac(long h,long ret){
        long sum = ret;
        if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        }
        return sum;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long mainsum = clac(h, (long)0);
        System.out.println(mainsum);
    } main {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long mainsum = clac(h, (long)0);
        System.out.println(mainsum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long mainsum = clac(h, (long)0); mainsum clac(h, (long)0) clac h (long)0 System.out.println(mainsum) System.out.println System.out System System.out mainsum String[] args args public static long clac(long h,long ret){
        long sum = ret;
        if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        }
        return sum;
    } clac {
        long sum = ret;
        if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        }
        return sum;
    } long sum = ret; sum ret if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        } h == 1 h 1 {
            sum ++;
        } sum ++ sum {
            sum = clac(h/2,sum) * 2 + 1;
        } sum = clac(h/2,sum) * 2 + 1 sum clac(h/2,sum) * 2 + 1 clac(h/2,sum) * 2 clac(h/2,sum) clac h/2 h 2 sum 2 1 return sum; sum long h h long ret ret public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long mainsum = clac(h, (long)0);
        System.out.println(mainsum);
    }
    public static long clac(long h,long ret){
        long sum = ret;
        if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        }
        return sum;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long mainsum = clac(h, (long)0);
        System.out.println(mainsum);
    }
    public static long clac(long h,long ret){
        long sum = ret;
        if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        }
        return sum;
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long mainsum = clac(h, (long)0);
        System.out.println(mainsum);
    }
    public static long clac(long h,long ret){
        long sum = ret;
        if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        }
        return sum;
    }
}