import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long h = Long.valueOf(arr01[0]);

        if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        }

    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long h = Long.valueOf(arr01[0]);

        if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        }

    }
} Main public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long h = Long.valueOf(arr01[0]);

        if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        }

    } main {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long h = Long.valueOf(arr01[0]);

        if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        }

    } InputStreamReader is = new InputStreamReader(System.in); is new InputStreamReader(System.in) BufferedReader reader = new BufferedReader(is); reader new BufferedReader(is) List<String> mylist = new ArrayList<>(); mylist new ArrayList<>() String strinput = reader.readLine(); strinput reader.readLine() reader.readLine reader while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        } strinput != null strinput null {

            mylist.add(strinput);
            strinput = reader.readLine();

        } mylist.add(strinput) mylist.add mylist strinput strinput = reader.readLine() strinput reader.readLine() reader.readLine reader String arr01[] = mylist.get(0).split(" "); arr01 mylist.get(0).split(" ") mylist.get(0).split mylist.get(0) mylist.get mylist 0 " " long h = Long.valueOf(arr01[0]); h Long.valueOf(arr01[0]) Long.valueOf Long arr01[0] arr01 0 if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        } h == 1 h 1 {
            System.out.println(1);
        } System.out.println(1) System.out.println System.out System System.out 1 {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        } long cnt = 0; cnt 0 long temp = 1; temp 1 long mysum = 0; mysum 0 while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            } h / 2 >= 2 h / 2 h 2 2 {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            } h = h / 2 h h / 2 h 2 cnt += 1 cnt 1 mysum += temp mysum temp temp *= 2 temp 2 double ans = mysum + Math.pow(2, cnt) * 3; ans mysum + Math.pow(2, cnt) * 3 mysum Math.pow(2, cnt) * 3 Math.pow(2, cnt) Math.pow Math 2 cnt 3 System.out.println((long) ans) System.out.println System.out System System.out (long) ans String[] args args public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long h = Long.valueOf(arr01[0]);

        if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        }

    }
} public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long h = Long.valueOf(arr01[0]);

        if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        }

    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long h = Long.valueOf(arr01[0]);

        if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        }

    }
}
