import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long  H = sc.nextLong();

        System.out.println(dfs(H));

    }

    static private long dfs(long h){
        if(h==1) return 1;

        long time = dfs(h/2)*2 + 1;

        return time;
    }


} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long  H = sc.nextLong();

        System.out.println(dfs(H));

    }

    static private long dfs(long h){
        if(h==1) return 1;

        long time = dfs(h/2)*2 + 1;

        return time;
    }


} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long  H = sc.nextLong();

        System.out.println(dfs(H));

    } main {
        Scanner sc = new Scanner(System.in);
        long  H = sc.nextLong();

        System.out.println(dfs(H));

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long  H = sc.nextLong(); H sc.nextLong() sc.nextLong sc System.out.println(dfs(H)) System.out.println System.out System System.out dfs(H) dfs H String[] args args static private long dfs(long h){
        if(h==1) return 1;

        long time = dfs(h/2)*2 + 1;

        return time;
    } dfs {
        if(h==1) return 1;

        long time = dfs(h/2)*2 + 1;

        return time;
    } if(h==1) return 1; h==1 h 1 return 1; 1 long time = dfs(h/2)*2 + 1; time dfs(h/2)*2 + 1 dfs(h/2)*2 dfs(h/2) dfs h/2 h 2 2 1 return time; time long h h public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long  H = sc.nextLong();

        System.out.println(dfs(H));

    }

    static private long dfs(long h){
        if(h==1) return 1;

        long time = dfs(h/2)*2 + 1;

        return time;
    }


} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long  H = sc.nextLong();

        System.out.println(dfs(H));

    }

    static private long dfs(long h){
        if(h==1) return 1;

        long time = dfs(h/2)*2 + 1;

        return time;
    }


} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long  H = sc.nextLong();

        System.out.println(dfs(H));

    }

    static private long dfs(long h){
        if(h==1) return 1;

        long time = dfs(h/2)*2 + 1;

        return time;
    }


}
