import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long h=sc.nextLong();
        long cntr=0,sum=0;
        while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        }
        sum+=(long)Math.pow(2,cntr);
        System.out.println(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 cntr=0,sum=0;
        while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        }
        sum+=(long)Math.pow(2,cntr);
        System.out.println(sum);
    }
} Main public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long h=sc.nextLong();
        long cntr=0,sum=0;
        while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        }
        sum+=(long)Math.pow(2,cntr);
        System.out.println(sum);
    } main {
        Scanner sc=new Scanner(System.in);
        long h=sc.nextLong();
        long cntr=0,sum=0;
        while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        }
        sum+=(long)Math.pow(2,cntr);
        System.out.println(sum);
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) long h=sc.nextLong(); h sc.nextLong() sc.nextLong sc long cntr=0 cntr 0 sum=0; sum 0 while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        } h!=1 h 1 {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        } sum+=(long)Math.pow(2,cntr) sum (long)Math.pow(2,cntr) Math.pow Math 2 cntr h/=2 h 2 cntr++ cntr sum+=(long)Math.pow(2,cntr) sum (long)Math.pow(2,cntr) Math.pow Math 2 cntr System.out.println(sum) System.out.println System.out System System.out sum String args[] args public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long h=sc.nextLong();
        long cntr=0,sum=0;
        while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        }
        sum+=(long)Math.pow(2,cntr);
        System.out.println(sum);
    }
} public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long h=sc.nextLong();
        long cntr=0,sum=0;
        while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        }
        sum+=(long)Math.pow(2,cntr);
        System.out.println(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 cntr=0,sum=0;
        while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        }
        sum+=(long)Math.pow(2,cntr);
        System.out.println(sum);
    }
}