import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private long calc(long H, Map<Long, Long> map) {
        if (map.containsKey(H)) {
            return map.get(H);
        }

        long nr = calc(H/2, map) + calc(H/2, map) + 1;
        map.put(H, nr);

        return nr;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();

        Map<Long, Long> map = new HashMap<Long, Long>();
        map.put(0L, 0L);
        map.put(1L, 1L);

        long ret = calc(H, map);
        System.out.println(ret);

        return;
    }

} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
} Main public static void main(String[] args) {
        new Solver().run();
    } main {
        new Solver().run();
    } new Solver().run() new Solver().run new Solver() String[] args args class Solver {

    private long calc(long H, Map<Long, Long> map) {
        if (map.containsKey(H)) {
            return map.get(H);
        }

        long nr = calc(H/2, map) + calc(H/2, map) + 1;
        map.put(H, nr);

        return nr;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();

        Map<Long, Long> map = new HashMap<Long, Long>();
        map.put(0L, 0L);
        map.put(1L, 1L);

        long ret = calc(H, map);
        System.out.println(ret);

        return;
    }

} Solver private long calc(long H, Map<Long, Long> map) {
        if (map.containsKey(H)) {
            return map.get(H);
        }

        long nr = calc(H/2, map) + calc(H/2, map) + 1;
        map.put(H, nr);

        return nr;
    } calc {
        if (map.containsKey(H)) {
            return map.get(H);
        }

        long nr = calc(H/2, map) + calc(H/2, map) + 1;
        map.put(H, nr);

        return nr;
    } if (map.containsKey(H)) {
            return map.get(H);
        } map.containsKey(H) map.containsKey map H {
            return map.get(H);
        } return map.get(H); map.get(H) map.get map H long nr = calc(H/2, map) + calc(H/2, map) + 1; nr calc(H/2, map) + calc(H/2, map) + 1 calc(H/2, map) + calc(H/2, map) + 1 calc(H/2, map) calc H/2 H 2 map calc(H/2, map) calc H/2 H 2 map 1 map.put(H, nr) map.put map H nr return nr; nr long H H Map<Long, Long> map map public void run() {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();

        Map<Long, Long> map = new HashMap<Long, Long>();
        map.put(0L, 0L);
        map.put(1L, 1L);

        long ret = calc(H, map);
        System.out.println(ret);

        return;
    } run {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();

        Map<Long, Long> map = new HashMap<Long, Long>();
        map.put(0L, 0L);
        map.put(1L, 1L);

        long ret = calc(H, map);
        System.out.println(ret);

        return;
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc Map<Long, Long> map = new HashMap<Long, Long>(); map new HashMap<Long, Long>() map.put(0L, 0L) map.put map 0L 0L map.put(1L, 1L) map.put map 1L 1L long ret = calc(H, map); ret calc(H, map) calc H map System.out.println(ret) System.out.println System.out System System.out ret return;
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private long calc(long H, Map<Long, Long> map) {
        if (map.containsKey(H)) {
            return map.get(H);
        }

        long nr = calc(H/2, map) + calc(H/2, map) + 1;
        map.put(H, nr);

        return nr;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();

        Map<Long, Long> map = new HashMap<Long, Long>();
        map.put(0L, 0L);
        map.put(1L, 1L);

        long ret = calc(H, map);
        System.out.println(ret);

        return;
    }

}