import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println(run());
    }

    private static ArrayList<Integer> nScan(Scanner sc, int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    private static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        }
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        System.out.println(run());
    }

    private static ArrayList<Integer> nScan(Scanner sc, int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    private static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        }
    }
} Main public static void main(String[] args) {
        System.out.println(run());
    } main {
        System.out.println(run());
    } System.out.println(run()) System.out.println System.out System System.out run() run String[] args args private static ArrayList<Integer> nScan(Scanner sc, int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    } nScan {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    } ArrayList<Integer> al = new ArrayList<>(); al new ArrayList<>() for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            al.add(sc.nextInt());
        } {
            al.add(sc.nextInt());
        } al.add(sc.nextInt()) al.add al sc.nextInt() sc.nextInt sc return al; al Scanner sc sc int n n private static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        }
    } run {
        try (Scanner sc = new Scanner(System.in);) {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        }
    } try (Scanner sc = new Scanner(System.in);) {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        } {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) long h = sc.nextLong() h sc.nextLong() sc.nextLong sc result = 0; result 0 for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            } long i = 1; long i = 1; i 1 h != 0 h 0 i *= 2 i *= 2 i 2 {
                result += i;
                h = (long) Math.floor(h / 2);
            } {
                result += i;
                h = (long) Math.floor(h / 2);
            } result += i result i h = (long) Math.floor(h / 2) h (long) Math.floor(h / 2) Math.floor Math h / 2 h 2 return result; result public class Main {
    public static void main(String[] args) {
        System.out.println(run());
    }

    private static ArrayList<Integer> nScan(Scanner sc, int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    private static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        }
    }
} public class Main {
    public static void main(String[] args) {
        System.out.println(run());
    }

    private static ArrayList<Integer> nScan(Scanner sc, int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    private static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        }
    }
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println(run());
    }

    private static ArrayList<Integer> nScan(Scanner sc, int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    private static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            long h = sc.nextLong(), result = 0;
            for (long i = 1; h != 0; i *= 2) {
                result += i;
                h = (long) Math.floor(h / 2);
            }
            return result;
        }
    }
}