import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        sc.close();
        long count = atackEnemy(H);

        System.out.println(count);
    }

    public static long atackEnemy(Long H) {
        if (H.equals(1L)) {
            return 1;
        } else {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        }
    }

} import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util import java.util.stream.Collectors; Collectors java.util.stream public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        sc.close();
        long count = atackEnemy(H);

        System.out.println(count);
    }

    public static long atackEnemy(Long H) {
        if (H.equals(1L)) {
            return 1;
        } else {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        }
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        sc.close();
        long count = atackEnemy(H);

        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        sc.close();
        long count = atackEnemy(H);

        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 sc.close() sc.close sc long count = atackEnemy(H); count atackEnemy(H) atackEnemy H System.out.println(count) System.out.println System.out System System.out count String[] args args public static long atackEnemy(Long H) {
        if (H.equals(1L)) {
            return 1;
        } else {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        }
    } atackEnemy {
        if (H.equals(1L)) {
            return 1;
        } else {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        }
    } if (H.equals(1L)) {
            return 1;
        } else {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        } H.equals(1L) H.equals H 1L {
            return 1;
        } return 1; 1 {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        } long newHp = H / 2; newHp H / 2 H 2 return 2 * atackEnemy(newHp) + 1; 2 * atackEnemy(newHp) + 1 2 * atackEnemy(newHp) 2 atackEnemy(newHp) atackEnemy newHp 1 Long H H public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        sc.close();
        long count = atackEnemy(H);

        System.out.println(count);
    }

    public static long atackEnemy(Long H) {
        if (H.equals(1L)) {
            return 1;
        } else {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        }
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        sc.close();
        long count = atackEnemy(H);

        System.out.println(count);
    }

    public static long atackEnemy(Long H) {
        if (H.equals(1L)) {
            return 1;
        } else {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        }
    }

} Main
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        sc.close();
        long count = atackEnemy(H);

        System.out.println(count);
    }

    public static long atackEnemy(Long H) {
        if (H.equals(1L)) {
            return 1;
        } else {
            long newHp = H / 2;
            return 2 * atackEnemy(newHp) + 1;
        }
    }

}