import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h=sc.nextLong();
        HashMap<Long,Long> map=new HashMap<>();
        long res = dfs(h,map);
        System.out.println(res);
    }

    public static long dfs(long h,HashMap<Long,Long> map)
    {
        long ans=1;
        if(h<=1)return ans;
        if(map.get(h)!=null)return map.get(h);
        long cur=dfs(h/2,map);
        ans+=2*cur;
        map.put(h,ans);
        return ans;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h=sc.nextLong();
        HashMap<Long,Long> map=new HashMap<>();
        long res = dfs(h,map);
        System.out.println(res);
    }

    public static long dfs(long h,HashMap<Long,Long> map)
    {
        long ans=1;
        if(h<=1)return ans;
        if(map.get(h)!=null)return map.get(h);
        long cur=dfs(h/2,map);
        ans+=2*cur;
        map.put(h,ans);
        return ans;
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h=sc.nextLong();
        HashMap<Long,Long> map=new HashMap<>();
        long res = dfs(h,map);
        System.out.println(res);
    } main {
        Scanner sc = new Scanner(System.in);
        long h=sc.nextLong();
        HashMap<Long,Long> map=new HashMap<>();
        long res = dfs(h,map);
        System.out.println(res);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h=sc.nextLong(); h sc.nextLong() sc.nextLong sc HashMap<Long,Long> map=new HashMap<>(); map new HashMap<>() long res = dfs(h,map); res dfs(h,map) dfs h map System.out.println(res) System.out.println System.out System System.out res String[] args args public static long dfs(long h,HashMap<Long,Long> map)
    {
        long ans=1;
        if(h<=1)return ans;
        if(map.get(h)!=null)return map.get(h);
        long cur=dfs(h/2,map);
        ans+=2*cur;
        map.put(h,ans);
        return ans;
    } dfs {
        long ans=1;
        if(h<=1)return ans;
        if(map.get(h)!=null)return map.get(h);
        long cur=dfs(h/2,map);
        ans+=2*cur;
        map.put(h,ans);
        return ans;
    } long ans=1; ans 1 if(h<=1)return ans; h<=1 h 1 return ans; ans if(map.get(h)!=null)return map.get(h); map.get(h)!=null map.get(h) map.get map h null return map.get(h); map.get(h) map.get map h long cur=dfs(h/2,map); cur dfs(h/2,map) dfs h/2 h 2 map ans+=2*cur ans 2*cur 2 cur map.put(h,ans) map.put map h ans return ans; ans long h h HashMap<Long,Long> map map public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h=sc.nextLong();
        HashMap<Long,Long> map=new HashMap<>();
        long res = dfs(h,map);
        System.out.println(res);
    }

    public static long dfs(long h,HashMap<Long,Long> map)
    {
        long ans=1;
        if(h<=1)return ans;
        if(map.get(h)!=null)return map.get(h);
        long cur=dfs(h/2,map);
        ans+=2*cur;
        map.put(h,ans);
        return ans;
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h=sc.nextLong();
        HashMap<Long,Long> map=new HashMap<>();
        long res = dfs(h,map);
        System.out.println(res);
    }

    public static long dfs(long h,HashMap<Long,Long> map)
    {
        long ans=1;
        if(h<=1)return ans;
        if(map.get(h)!=null)return map.get(h);
        long cur=dfs(h/2,map);
        ans+=2*cur;
        map.put(h,ans);
        return ans;
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h=sc.nextLong();
        HashMap<Long,Long> map=new HashMap<>();
        long res = dfs(h,map);
        System.out.println(res);
    }

    public static long dfs(long h,HashMap<Long,Long> map)
    {
        long ans=1;
        if(h<=1)return ans;
        if(map.get(h)!=null)return map.get(h);
        long cur=dfs(h/2,map);
        ans+=2*cur;
        map.put(h,ans);
        return ans;
    }
}