import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long h = Long.parseLong(sc.next());

        // 主処理
        long count = 0;
        long result = 0;
        if (1 < h) {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } else {
            result++;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long h = Long.parseLong(sc.next());

        // 主処理
        long count = 0;
        long result = 0;
        if (1 < h) {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } else {
            result++;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
} Main public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long h = Long.parseLong(sc.next());

        // 主処理
        long count = 0;
        long result = 0;
        if (1 < h) {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } else {
            result++;
        }

        // 出力
        System.out.println(result);
        sc.close();
    } main {

        // 入力
        Scanner sc = new Scanner(System.in);
        long h = Long.parseLong(sc.next());

        // 主処理
        long count = 0;
        long result = 0;
        if (1 < h) {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } else {
            result++;
        }

        // 出力
        System.out.println(result);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = Long.parseLong(sc.next()); h Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long count = 0; count 0 long result = 0; result 0 if (1 < h) {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } else {
            result++;
        } 1 < h 1 h {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } h = (long) Math.ceil(h / 2) h (long) Math.ceil(h / 2) Math.ceil Math h / 2 h 2 count++ count result += count result count while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            } 1 < h 1 h {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            } h = (long) Math.ceil(h / 2) h (long) Math.ceil(h / 2) Math.ceil Math h / 2 h 2 count *= 2 count 2 result += count result count h = (long) Math.ceil(h / 2) h (long) Math.ceil(h / 2) Math.ceil Math h / 2 h 2 count *= 2 count 2 result += count result count {
            result++;
        } result++ result System.out.println(result) System.out.println System.out System System.out result sc.close() sc.close sc String args[] args public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long h = Long.parseLong(sc.next());

        // 主処理
        long count = 0;
        long result = 0;
        if (1 < h) {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } else {
            result++;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
} public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long h = Long.parseLong(sc.next());

        // 主処理
        long count = 0;
        long result = 0;
        if (1 < h) {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } else {
            result++;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long h = Long.parseLong(sc.next());

        // 主処理
        long count = 0;
        long result = 0;
        if (1 < h) {
            h = (long) Math.ceil(h / 2);
            count++;
            result += count;
            while (1 < h) {
                h = (long) Math.ceil(h / 2);
                count *= 2;
                result += count;
            }
            h = (long) Math.ceil(h / 2);
            count *= 2;
            result += count;
        } else {
            result++;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}