import java.io.*;
import java.util.*;

public class Main {
    public static HashMap<Long, Long> map;

    public static void main(String args[]) {
        InputOutput io = new InputOutput(System.in, System.out);
        long h = io.l();
        map = new HashMap<>();
        io.pln(hit(h));
        io.flush();
    }
    
    public static long hit(long h) {
        if (h == 1)
            return 1;
        if (map.containsKey(h))
            return map.get(h);
        long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1;
        map.put(h, ans);
        return ans;
    }

    public static class InputOutput {
        private BufferedReader br;
        private StringTokenizer tok;
        private PrintWriter pw;

        InputOutput(InputStream inputStream, OutputStream outputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        }

        public String s() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        }

        public int i() {
            return Integer.parseInt(this.s());
        }

        public long l() {
            return Long.parseLong(this.s());
        }

        public void p(Object... out) {
            for (Object e : out)
                pw.print(e.toString());
        }

        public <T> void pln(T out) {
            pw.println(out);
        }

        public void pln() {
            pw.println();
        }

        public void flush() {
            pw.flush();
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static HashMap<Long, Long> map;

    public static void main(String args[]) {
        InputOutput io = new InputOutput(System.in, System.out);
        long h = io.l();
        map = new HashMap<>();
        io.pln(hit(h));
        io.flush();
    }
    
    public static long hit(long h) {
        if (h == 1)
            return 1;
        if (map.containsKey(h))
            return map.get(h);
        long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1;
        map.put(h, ans);
        return ans;
    }

    public static class InputOutput {
        private BufferedReader br;
        private StringTokenizer tok;
        private PrintWriter pw;

        InputOutput(InputStream inputStream, OutputStream outputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        }

        public String s() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        }

        public int i() {
            return Integer.parseInt(this.s());
        }

        public long l() {
            return Long.parseLong(this.s());
        }

        public void p(Object... out) {
            for (Object e : out)
                pw.print(e.toString());
        }

        public <T> void pln(T out) {
            pw.println(out);
        }

        public void pln() {
            pw.println();
        }

        public void flush() {
            pw.flush();
        }
    }
} Main public static HashMap<Long, Long> map; map public static void main(String args[]) {
        InputOutput io = new InputOutput(System.in, System.out);
        long h = io.l();
        map = new HashMap<>();
        io.pln(hit(h));
        io.flush();
    } main {
        InputOutput io = new InputOutput(System.in, System.out);
        long h = io.l();
        map = new HashMap<>();
        io.pln(hit(h));
        io.flush();
    } InputOutput io = new InputOutput(System.in, System.out); io new InputOutput(System.in, System.out) long h = io.l(); h io.l() io.l io map = new HashMap<>() map new HashMap<>() io.pln(hit(h)) io.pln io hit(h) hit h io.flush() io.flush io String args[] args public static long hit(long h) {
        if (h == 1)
            return 1;
        if (map.containsKey(h))
            return map.get(h);
        long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1;
        map.put(h, ans);
        return ans;
    } hit {
        if (h == 1)
            return 1;
        if (map.containsKey(h))
            return map.get(h);
        long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1;
        map.put(h, ans);
        return ans;
    } if (h == 1)
            return 1; h == 1 h 1 return 1; 1 if (map.containsKey(h))
            return map.get(h); map.containsKey(h) map.containsKey map h return map.get(h); map.get(h) map.get map h long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1; ans hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1 hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1 hit((long) Math.floor(h / 2)) hit (long) Math.floor(h / 2) Math.floor Math h / 2 h 2 hit((long) Math.floor(h / 2)) hit (long) Math.floor(h / 2) Math.floor Math h / 2 h 2 1 map.put(h, ans) map.put map h ans return ans; ans long h h public static class InputOutput {
        private BufferedReader br;
        private StringTokenizer tok;
        private PrintWriter pw;

        InputOutput(InputStream inputStream, OutputStream outputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        }

        public String s() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        }

        public int i() {
            return Integer.parseInt(this.s());
        }

        public long l() {
            return Long.parseLong(this.s());
        }

        public void p(Object... out) {
            for (Object e : out)
                pw.print(e.toString());
        }

        public <T> void pln(T out) {
            pw.println(out);
        }

        public void pln() {
            pw.println();
        }

        public void flush() {
            pw.flush();
        }
    } InputOutput private BufferedReader br; br private StringTokenizer tok; tok private PrintWriter pw; pw InputOutput(InputStream inputStream, OutputStream outputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        } InputOutput {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        } br = new BufferedReader(new InputStreamReader(inputStream)) br new BufferedReader(new InputStreamReader(inputStream)) pw = new PrintWriter(new OutputStreamWriter(outputStream)) pw new PrintWriter(new OutputStreamWriter(outputStream)) InputStream inputStream inputStream OutputStream outputStream outputStream public String s() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        } s {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        } while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            } tok == null || !tok.hasMoreElements() tok == null tok null !tok.hasMoreElements() tok.hasMoreElements() tok.hasMoreElements tok {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            } try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                } catch (IOException exc) {
                    exc.printStackTrace();
                } IOException exc {
                    exc.printStackTrace();
                } exc.printStackTrace() exc.printStackTrace exc {
                    tok = new StringTokenizer(br.readLine());
                } tok = new StringTokenizer(br.readLine()) tok new StringTokenizer(br.readLine()) return tok.nextToken(); tok.nextToken() tok.nextToken tok public int i() {
            return Integer.parseInt(this.s());
        } i {
            return Integer.parseInt(this.s());
        } return Integer.parseInt(this.s()); Integer.parseInt(this.s()) Integer.parseInt Integer this.s() this.s this public long l() {
            return Long.parseLong(this.s());
        } l {
            return Long.parseLong(this.s());
        } return Long.parseLong(this.s()); Long.parseLong(this.s()) Long.parseLong Long this.s() this.s this public void p(Object... out) {
            for (Object e : out)
                pw.print(e.toString());
        } p {
            for (Object e : out)
                pw.print(e.toString());
        } for (Object e : out)
                pw.print(e.toString()); Object e out pw.print(e.toString()); pw.print(e.toString()) pw.print pw e.toString() e.toString e Object... out out public <T> void pln(T out) {
            pw.println(out);
        } pln {
            pw.println(out);
        } pw.println(out) pw.println pw out T out out public void pln() {
            pw.println();
        } pln {
            pw.println();
        } pw.println() pw.println pw public void flush() {
            pw.flush();
        } flush {
            pw.flush();
        } pw.flush() pw.flush pw public class Main {
    public static HashMap<Long, Long> map;

    public static void main(String args[]) {
        InputOutput io = new InputOutput(System.in, System.out);
        long h = io.l();
        map = new HashMap<>();
        io.pln(hit(h));
        io.flush();
    }
    
    public static long hit(long h) {
        if (h == 1)
            return 1;
        if (map.containsKey(h))
            return map.get(h);
        long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1;
        map.put(h, ans);
        return ans;
    }

    public static class InputOutput {
        private BufferedReader br;
        private StringTokenizer tok;
        private PrintWriter pw;

        InputOutput(InputStream inputStream, OutputStream outputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        }

        public String s() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        }

        public int i() {
            return Integer.parseInt(this.s());
        }

        public long l() {
            return Long.parseLong(this.s());
        }

        public void p(Object... out) {
            for (Object e : out)
                pw.print(e.toString());
        }

        public <T> void pln(T out) {
            pw.println(out);
        }

        public void pln() {
            pw.println();
        }

        public void flush() {
            pw.flush();
        }
    }
} public class Main {
    public static HashMap<Long, Long> map;

    public static void main(String args[]) {
        InputOutput io = new InputOutput(System.in, System.out);
        long h = io.l();
        map = new HashMap<>();
        io.pln(hit(h));
        io.flush();
    }
    
    public static long hit(long h) {
        if (h == 1)
            return 1;
        if (map.containsKey(h))
            return map.get(h);
        long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1;
        map.put(h, ans);
        return ans;
    }

    public static class InputOutput {
        private BufferedReader br;
        private StringTokenizer tok;
        private PrintWriter pw;

        InputOutput(InputStream inputStream, OutputStream outputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        }

        public String s() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        }

        public int i() {
            return Integer.parseInt(this.s());
        }

        public long l() {
            return Long.parseLong(this.s());
        }

        public void p(Object... out) {
            for (Object e : out)
                pw.print(e.toString());
        }

        public <T> void pln(T out) {
            pw.println(out);
        }

        public void pln() {
            pw.println();
        }

        public void flush() {
            pw.flush();
        }
    }
} Main
import java.io.*;
import java.util.*;

public class Main {
    public static HashMap<Long, Long> map;

    public static void main(String args[]) {
        InputOutput io = new InputOutput(System.in, System.out);
        long h = io.l();
        map = new HashMap<>();
        io.pln(hit(h));
        io.flush();
    }
    
    public static long hit(long h) {
        if (h == 1)
            return 1;
        if (map.containsKey(h))
            return map.get(h);
        long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1;
        map.put(h, ans);
        return ans;
    }

    public static class InputOutput {
        private BufferedReader br;
        private StringTokenizer tok;
        private PrintWriter pw;

        InputOutput(InputStream inputStream, OutputStream outputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        }

        public String s() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        }

        public int i() {
            return Integer.parseInt(this.s());
        }

        public long l() {
            return Long.parseLong(this.s());
        }

        public void p(Object... out) {
            for (Object e : out)
                pw.print(e.toString());
        }

        public <T> void pln(T out) {
            pw.println(out);
        }

        public void pln() {
            pw.println();
        }

        public void flush() {
            pw.flush();
        }
    }
}