import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        if (h < 2) {
            System.out.println(h);
            return ;
        }
        // how 2:pow
        int p = 0;
        while (true) {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        }

        long[] memo = new long[p+1];
        memo[1] = 3;
        for (int i=2;i<=p;i++) {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        }

        System.out.println(memo[p]);

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        if (h < 2) {
            System.out.println(h);
            return ;
        }
        // how 2:pow
        int p = 0;
        while (true) {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        }

        long[] memo = new long[p+1];
        memo[1] = 3;
        for (int i=2;i<=p;i++) {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        }

        System.out.println(memo[p]);

    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        if (h < 2) {
            System.out.println(h);
            return ;
        }
        // how 2:pow
        int p = 0;
        while (true) {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        }

        long[] memo = new long[p+1];
        memo[1] = 3;
        for (int i=2;i<=p;i++) {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        }

        System.out.println(memo[p]);

    } main {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        if (h < 2) {
            System.out.println(h);
            return ;
        }
        // how 2:pow
        int p = 0;
        while (true) {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        }

        long[] memo = new long[p+1];
        memo[1] = 3;
        for (int i=2;i<=p;i++) {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        }

        System.out.println(memo[p]);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc if (h < 2) {
            System.out.println(h);
            return ;
        } h < 2 h 2 {
            System.out.println(h);
            return ;
        } System.out.println(h) System.out.println System.out System System.out h return ; int p = 0; p 0 while (true) {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        } true {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        } double p1 = Math.pow(2, p); p1 Math.pow(2, p) Math.pow Math 2 p double p2 = Math.pow(2, p+1); p2 Math.pow(2, p+1) Math.pow Math 2 p+1 p 1 if (p1 <= h && h < p2) {
                break;
            } p1 <= h && h < p2 p1 <= h p1 h h < p2 h p2 {
                break;
            } break; p++ p long[] memo = new long[p+1]; memo new long[p+1] p+1 p 1 memo[1] = 3 memo[1] memo 1 3 for (int i=2;i<=p;i++) {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        } int i=2; int i=2; i 2 i<=p i p i++ i++ i {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        } {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        } memo[i] = (memo[i - 1] - 1) * 2 + 3 memo[i] memo i (memo[i - 1] - 1) * 2 + 3 (memo[i - 1] - 1) * 2 (memo[i - 1] - 1) memo[i - 1] memo i - 1 i 1 1 2 3 System.out.println(memo[p]) System.out.println System.out System System.out memo[p] memo p String[] args args public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        if (h < 2) {
            System.out.println(h);
            return ;
        }
        // how 2:pow
        int p = 0;
        while (true) {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        }

        long[] memo = new long[p+1];
        memo[1] = 3;
        for (int i=2;i<=p;i++) {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        }

        System.out.println(memo[p]);

    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        if (h < 2) {
            System.out.println(h);
            return ;
        }
        // how 2:pow
        int p = 0;
        while (true) {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        }

        long[] memo = new long[p+1];
        memo[1] = 3;
        for (int i=2;i<=p;i++) {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        }

        System.out.println(memo[p]);

    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        if (h < 2) {
            System.out.println(h);
            return ;
        }
        // how 2:pow
        int p = 0;
        while (true) {
            double p1 = Math.pow(2, p);
            double p2 = Math.pow(2, p+1);
            if (p1 <= h && h < p2) {
                break;
            }
            p++;
        }

        long[] memo = new long[p+1];
        memo[1] = 3;
        for (int i=2;i<=p;i++) {
            memo[i] = (memo[i - 1] - 1) * 2 + 3;
        }

        System.out.println(memo[p]);

    }
}
