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(f(h));
    }

    private static long f(long x) {
        if (x == 1) return 1;
        long a = f(x/2);
        return a*2+1;
    }
} 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(f(h));
    }

    private static long f(long x) {
        if (x == 1) return 1;
        long a = f(x/2);
        return a*2+1;
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        System.out.println(f(h));
    } main {

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        System.out.println(f(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(f(h)) System.out.println System.out System System.out f(h) f h String[] args args private static long f(long x) {
        if (x == 1) return 1;
        long a = f(x/2);
        return a*2+1;
    } f {
        if (x == 1) return 1;
        long a = f(x/2);
        return a*2+1;
    } if (x == 1) return 1; x == 1 x 1 return 1; 1 long a = f(x/2); a f(x/2) f x/2 x 2 return a*2+1; a*2+1 a*2 a 2 1 long x x public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        System.out.println(f(h));
    }

    private static long f(long x) {
        if (x == 1) return 1;
        long a = f(x/2);
        return a*2+1;
    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        System.out.println(f(h));
    }

    private static long f(long x) {
        if (x == 1) return 1;
        long a = f(x/2);
        return a*2+1;
    }
} 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(f(h));
    }

    private static long f(long x) {
        if (x == 1) return 1;
        long a = f(x/2);
        return a*2+1;
    }
}
