import java.util.*;

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

        long attacks = 0;
        long level = 1;
        while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        }
        System.out.println(attacks);
    }
} 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 attacks = 0;
        long level = 1;
        while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        }
        System.out.println(attacks);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();

        long attacks = 0;
        long level = 1;
        while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        }
        System.out.println(attacks);
    } main {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();

        long attacks = 0;
        long level = 1;
        while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        }
        System.out.println(attacks);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long attacks = 0; attacks 0 long level = 1; level 1 while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        } h != 0 h 0 {
            h = h/2;
            attacks += level;
            level *= 2;
        } h = h/2 h h/2 h 2 attacks += level attacks level level *= 2 level 2 System.out.println(attacks) System.out.println System.out System System.out attacks String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();

        long attacks = 0;
        long level = 1;
        while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        }
        System.out.println(attacks);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();

        long attacks = 0;
        long level = 1;
        while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        }
        System.out.println(attacks);
    }
} Main
import java.util.*;

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

        long attacks = 0;
        long level = 1;
        while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        }
        System.out.println(attacks);
    }
}