import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long H = Long.parseLong(s.next());
        System.out.println(atack(H));
    }

    // 再帰でやるとこう
    static long atack(long h) {
        if (h == 1) {
            return 1;
        }
        return atack(h / 2) * 2 + 1;
    }

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

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long H = Long.parseLong(s.next());
        System.out.println(atack(H));
    }

    // 再帰でやるとこう
    static long atack(long h) {
        if (h == 1) {
            return 1;
        }
        return atack(h / 2) * 2 + 1;
    }

} Main public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long H = Long.parseLong(s.next());
        System.out.println(atack(H));
    } main {
        Scanner s = new Scanner(System.in);
        long H = Long.parseLong(s.next());
        System.out.println(atack(H));
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) long H = Long.parseLong(s.next()); H Long.parseLong(s.next()) Long.parseLong Long s.next() s.next s System.out.println(atack(H)) System.out.println System.out System System.out atack(H) atack H String[] args args // 再帰でやるとこう
    static long atack(long h) {
        if (h == 1) {
            return 1;
        }
        return atack(h / 2) * 2 + 1;
    } atack {
        if (h == 1) {
            return 1;
        }
        return atack(h / 2) * 2 + 1;
    } if (h == 1) {
            return 1;
        } h == 1 h 1 {
            return 1;
        } return 1; 1 return atack(h / 2) * 2 + 1; atack(h / 2) * 2 + 1 atack(h / 2) * 2 atack(h / 2) atack h / 2 h 2 2 1 long h h public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long H = Long.parseLong(s.next());
        System.out.println(atack(H));
    }

    // 再帰でやるとこう
    static long atack(long h) {
        if (h == 1) {
            return 1;
        }
        return atack(h / 2) * 2 + 1;
    }

} public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long H = Long.parseLong(s.next());
        System.out.println(atack(H));
    }

    // 再帰でやるとこう
    static long atack(long h) {
        if (h == 1) {
            return 1;
        }
        return atack(h / 2) * 2 + 1;
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long H = Long.parseLong(s.next());
        System.out.println(atack(H));
    }

    // 再帰でやるとこう
    static long atack(long h) {
        if (h == 1) {
            return 1;
        }
        return atack(h / 2) * 2 + 1;
    }

}
