import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        long h = stdIn.nextLong();

        long monster = 1;
        long attack = 0;
        while (!(monster == 0)) {
            if (h / 2 == 0) {
                attack += monster;
                monster = 0;
            } else {
                h = h / 2;
                attack += monster;
                monster *= 2;
            }
        }
        System.out.println(attack);
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        long h = stdIn.nextLong();

        long monster = 1;
        long attack = 0;
        while (!(monster == 0)) {
            if (h / 2 == 0) {
                attack += monster;
                monster = 0;
            } else {
                h = h / 2;
                attack += monster;
                monster *= 2;
            }
        }
        System.out.println(attack);
    }
} Main public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        long h = stdIn.nextLong();

        long monster = 1;
        long attack = 0;
        while (!(monster == 0)) {
            if (h / 2 == 0) {
                attack += monster;
                monster = 0;
            } else {
                h = h / 2;
                attack += monster;
                monster *= 2;
            }
        }
        System.out.println(attack);
    } main {
        Scanner stdIn = new Scanner(System.in);

        long h = stdIn.nextLong();

        long monster = 1;
        long attack = 0;
        while (!(monster == 0)) {
            if (h / 2 == 0) {
                attack += monster;
                monster = 0;
            } else {
                h = h / 2;
                attack += monster;
                monster *= 2;
            }
        }
        System.out.println(attack);
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) long h = stdIn.nextLong(); h stdIn.nextLong() stdIn.nextLong stdIn long monster = 1; monster 1 long attack = 0; attack 0 while (!(monster == 0)) {
            if (h / 2 == 0) {
                attack += monster;
                monster = 0;
            } else {
                h = h / 2;
                attack += monster;
                monster *= 2;
            }
        } !(monster == 0) (monster == 0) monster 0 {
            if (h / 2 == 0) {
                attack += monster;
                monster = 0;
            } else {
                h = h / 2;
                attack += monster;
                monster *= 2;
            }
        } if (h / 2 == 0) {
                attack += monster;
                monster = 0;
            } else {
                h = h / 2;
                attack += monster;
                monster *= 2;
            } h / 2 == 0 h / 2 h 2 0 {
                attack += monster;
                monster = 0;
            } attack += monster attack monster monster = 0 monster 0 {
                h = h / 2;
                attack += monster;
                monster *= 2;
            } h = h / 2 h h / 2 h 2 attack += monster attack monster monster *= 2 monster 2 System.out.println(attack) System.out.println System.out System System.out attack String[] args args
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        long h = stdIn.nextLong();

        long monster = 1;
        long attack = 0;
        while (!(monster == 0)) {
            if (h / 2 == 0) {
                attack += monster;
                monster = 0;
            } else {
                h = h / 2;
                attack += monster;
                monster *= 2;
            }
        }
        System.out.println(attack);
    }
}
