import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long count = 0;
        long mCount = 1;
        while (H != 0) {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long count = 0;
        long mCount = 1;
        while (H != 0) {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long count = 0;
        long mCount = 1;
        while (H != 0) {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long count = 0;
        long mCount = 1;
        while (H != 0) {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc long count = 0; count 0 long mCount = 1; mCount 1 while (H != 0) {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        } H != 0 H 0 {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        } count += mCount count mCount mCount *= 2 mCount 2 if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            } H % 2 == 1 H % 2 H 2 1 {
                H = (H - 1) / 2;
            } H = (H - 1) / 2 H (H - 1) / 2 (H - 1) H 1 2 {
                H = H / 2;
            } H = H / 2 H H / 2 H 2 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long count = 0;
        long mCount = 1;
        while (H != 0) {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long count = 0;
        long mCount = 1;
        while (H != 0) {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        }
        System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long count = 0;
        long mCount = 1;
        while (H != 0) {
            count += mCount;
            mCount *= 2;
            if (H % 2 == 1) {
                H = (H - 1) / 2;
            } else {
                H = H / 2;
            }
        }
        System.out.println(count);
    }
}