import java.util.Scanner;

public class Main {

    private static long solve(long H) {
        if (H <= 1L) {
            return 1L;
        } else {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        }
    }

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

        long H = sc.nextLong();
        // ツリーのノード数分だけ攻撃する必要がある.
        System.out.println(solve(H));
    }
} import java.util.Scanner; Scanner java.util public class Main {

    private static long solve(long H) {
        if (H <= 1L) {
            return 1L;
        } else {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        }
    }

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

        long H = sc.nextLong();
        // ツリーのノード数分だけ攻撃する必要がある.
        System.out.println(solve(H));
    }
} Main private static long solve(long H) {
        if (H <= 1L) {
            return 1L;
        } else {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        }
    } solve {
        if (H <= 1L) {
            return 1L;
        } else {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        }
    } if (H <= 1L) {
            return 1L;
        } else {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        } H <= 1L H 1L {
            return 1L;
        } return 1L; 1L {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        } return 2L * solve((long)Math.floor(H / (double)2)) + 1L; 2L * solve((long)Math.floor(H / (double)2)) + 1L 2L * solve((long)Math.floor(H / (double)2)) 2L solve((long)Math.floor(H / (double)2)) solve (long)Math.floor(H / (double)2) Math.floor Math H / (double)2 H (double)2 1L long H H public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        // ツリーのノード数分だけ攻撃する必要がある.
        System.out.println(solve(H));
    } main {
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        // ツリーのノード数分だけ攻撃する必要がある.
        System.out.println(solve(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(solve(H)) System.out.println System.out System System.out solve(H) solve H String[] args args public class Main {

    private static long solve(long H) {
        if (H <= 1L) {
            return 1L;
        } else {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        }
    }

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

        long H = sc.nextLong();
        // ツリーのノード数分だけ攻撃する必要がある.
        System.out.println(solve(H));
    }
} public class Main {

    private static long solve(long H) {
        if (H <= 1L) {
            return 1L;
        } else {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        }
    }

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

        long H = sc.nextLong();
        // ツリーのノード数分だけ攻撃する必要がある.
        System.out.println(solve(H));
    }
} Main
import java.util.Scanner;

public class Main {

    private static long solve(long H) {
        if (H <= 1L) {
            return 1L;
        } else {
            return 2L * solve((long)Math.floor(H / (double)2)) + 1L;
        }
    }

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

        long H = sc.nextLong();
        // ツリーのノード数分だけ攻撃する必要がある.
        System.out.println(solve(H));
    }
}
