import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC153D - Caracal vs Monster

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        if (h == 1) {
            System.out.println(1);
            return;
        }
        
        long x = h;
        int cnt = 0;
        while(true) {
            x /=2;
            cnt++;
            if (x == 1) break;
        }
        
        long ans = 2;
        for (int i = 0; i < cnt; i++) {
            ans *= 2;
        }
        
        if (cnt > 0) ans--;

        System.out.println(ans);
    }

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

    public static void main(String[] args) {
        // ABC153D - Caracal vs Monster

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        if (h == 1) {
            System.out.println(1);
            return;
        }
        
        long x = h;
        int cnt = 0;
        while(true) {
            x /=2;
            cnt++;
            if (x == 1) break;
        }
        
        long ans = 2;
        for (int i = 0; i < cnt; i++) {
            ans *= 2;
        }
        
        if (cnt > 0) ans--;

        System.out.println(ans);
    }

} Main public static void main(String[] args) {
        // ABC153D - Caracal vs Monster

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        if (h == 1) {
            System.out.println(1);
            return;
        }
        
        long x = h;
        int cnt = 0;
        while(true) {
            x /=2;
            cnt++;
            if (x == 1) break;
        }
        
        long ans = 2;
        for (int i = 0; i < cnt; i++) {
            ans *= 2;
        }
        
        if (cnt > 0) ans--;

        System.out.println(ans);
    } main {
        // ABC153D - Caracal vs Monster

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        if (h == 1) {
            System.out.println(1);
            return;
        }
        
        long x = h;
        int cnt = 0;
        while(true) {
            x /=2;
            cnt++;
            if (x == 1) break;
        }
        
        long ans = 2;
        for (int i = 0; i < cnt; i++) {
            ans *= 2;
        }
        
        if (cnt > 0) ans--;

        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc if (h == 1) {
            System.out.println(1);
            return;
        } h == 1 h 1 {
            System.out.println(1);
            return;
        } System.out.println(1) System.out.println System.out System System.out 1 return; long x = h; x h int cnt = 0; cnt 0 while(true) {
            x /=2;
            cnt++;
            if (x == 1) break;
        } true {
            x /=2;
            cnt++;
            if (x == 1) break;
        } x /=2 x 2 cnt++ cnt if (x == 1) break; x == 1 x 1 break; long ans = 2; ans 2 for (int i = 0; i < cnt; i++) {
            ans *= 2;
        } int i = 0; int i = 0; i 0 i < cnt i cnt i++ i++ i {
            ans *= 2;
        } {
            ans *= 2;
        } ans *= 2 ans 2 if (cnt > 0) ans--; cnt > 0 cnt 0 ans-- ans 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) {
        // ABC153D - Caracal vs Monster

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        if (h == 1) {
            System.out.println(1);
            return;
        }
        
        long x = h;
        int cnt = 0;
        while(true) {
            x /=2;
            cnt++;
            if (x == 1) break;
        }
        
        long ans = 2;
        for (int i = 0; i < cnt; i++) {
            ans *= 2;
        }
        
        if (cnt > 0) ans--;

        System.out.println(ans);
    }

} public class Main {

    public static void main(String[] args) {
        // ABC153D - Caracal vs Monster

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        if (h == 1) {
            System.out.println(1);
            return;
        }
        
        long x = h;
        int cnt = 0;
        while(true) {
            x /=2;
            cnt++;
            if (x == 1) break;
        }
        
        long ans = 2;
        for (int i = 0; i < cnt; i++) {
            ans *= 2;
        }
        
        if (cnt > 0) ans--;

        System.out.println(ans);
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC153D - Caracal vs Monster

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        if (h == 1) {
            System.out.println(1);
            return;
        }
        
        long x = h;
        int cnt = 0;
        while(true) {
            x /=2;
            cnt++;
            if (x == 1) break;
        }
        
        long ans = 2;
        for (int i = 0; i < cnt; i++) {
            ans *= 2;
        }
        
        if (cnt > 0) ans--;

        System.out.println(ans);
    }

}