
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 1;
        long ans = 0;
        for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        }
        System.out.println(ans);
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 1;
        long ans = 0;
        for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        }
        System.out.println(ans);
    }

} Main public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 1;
        long ans = 0;
        for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        }
        System.out.println(ans);
    } main {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 1;
        long ans = 0;
        for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        }
        System.out.println(ans);
    } @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long count = 1; count 1 long ans = 0; ans 0 for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        } int i = 0 ; int i = 0 ; i 0 i < 50 i 50 i++ i++ i {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        } {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        } if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            } h > 1 h 1 {
                ans += count;
                h /= 2;
                count *= 2;
            } ans += count ans count h /= 2 h 2 count *= 2 count 2 if (h == 1) {
                h = 0;
                ans += count;
            } h == 1 h 1 {
                h = 0;
                ans += count;
            } h = 0 h 0 ans += count ans count System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 1;
        long ans = 0;
        for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        }
        System.out.println(ans);
    }

} public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 1;
        long ans = 0;
        for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        }
        System.out.println(ans);
    }

} Main

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 1;
        long ans = 0;
        for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        }
        System.out.println(ans);
    }

}