import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.Map;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCaracalVsMonster solver = new DCaracalVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCaracalVsMonster {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long h = nl();
            TreeMap<Long, Long> tmap = new TreeMap<>();
            tmap.put(h, 1l);
            long ans = 0;
            while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            }
            pn(ans);
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.TreeMap; TreeMap java.util import java.util.Map; Map java.util import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCaracalVsMonster solver = new DCaracalVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCaracalVsMonster {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long h = nl();
            TreeMap<Long, Long> tmap = new TreeMap<>();
            tmap.put(h, 1l);
            long ans = 0;
            while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            }
            pn(ans);
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCaracalVsMonster solver = new DCaracalVsMonster();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCaracalVsMonster solver = new DCaracalVsMonster();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) DCaracalVsMonster solver = new DCaracalVsMonster(); solver new DCaracalVsMonster() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class DCaracalVsMonster {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long h = nl();
            TreeMap<Long, Long> tmap = new TreeMap<>();
            tmap.put(h, 1l);
            long ans = 0;
            while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            }
            pn(ans);
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    } DCaracalVsMonster PrintWriter out; out InputReader in; in public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long h = nl();
            TreeMap<Long, Long> tmap = new TreeMap<>();
            tmap.put(h, 1l);
            long ans = 0;
            while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            }
            pn(ans);
        } solve {
            this.out = out;
            this.in = in;
            long h = nl();
            TreeMap<Long, Long> tmap = new TreeMap<>();
            tmap.put(h, 1l);
            long ans = 0;
            while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            }
            pn(ans);
        } this.out = out this.out this this.out out this.in = in this.in this this.in in long h = nl(); h nl() nl TreeMap<Long, Long> tmap = new TreeMap<>(); tmap new TreeMap<>() tmap.put(h, 1l) tmap.put tmap h 1l long ans = 0; ans 0 while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            } tmap.size() > 0 tmap.size() tmap.size tmap 0 {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            } if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                } tmap.lastKey() == 1 tmap.lastKey() tmap.lastKey tmap 1 {
                    ans += tmap.get(tmap.lastKey());
                    break;
                } ans += tmap.get(tmap.lastKey()) ans tmap.get(tmap.lastKey()) tmap.get tmap tmap.lastKey() tmap.lastKey tmap break; long x = tmap.get(tmap.lastKey()); x tmap.get(tmap.lastKey()) tmap.get tmap tmap.lastKey() tmap.lastKey tmap long which = tmap.lastKey(); which tmap.lastKey() tmap.lastKey tmap tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x) tmap.put tmap which / 2 which 2 tmap.getOrDefault(which / 2, 0l) + 2 * x tmap.getOrDefault(which / 2, 0l) tmap.getOrDefault tmap which / 2 which 2 0l 2 * x 2 x ans += x ans x tmap.remove(which) tmap.remove tmap which pn(ans) pn ans int testNumber testNumber InputReader in in PrintWriter out out long nl() {
            return in.nextLong();
        } nl {
            return in.nextLong();
        } return in.nextLong(); in.nextLong() in.nextLong in void pn(long zx) {
            out.println(zx);
        } pn {
            out.println(zx);
        } out.println(zx) out.println out zx long zx zx static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    } InputReader private InputStream stream; stream private byte[] buf = new byte[1024]; buf new byte[1024] 1024 private int curChar; curChar private int numChars; numChars public InputReader(InputStream stream) {
            this.stream = stream;
        } InputReader {
            this.stream = stream;
        } this.stream = stream this.stream this this.stream stream InputStream stream stream public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        } read {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        } if (numChars == -1)
                throw new UnknownError(); numChars == -1 numChars -1 1 throw new UnknownError(); new UnknownError() if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            } curChar >= numChars curChar numChars {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            } curChar = 0 curChar 0 try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                } catch (IOException e) {
                    throw new UnknownError();
                } IOException e {
                    throw new UnknownError();
                } throw new UnknownError(); new UnknownError() {
                    numChars = stream.read(buf);
                } numChars = stream.read(buf) numChars stream.read(buf) stream.read stream buf if (numChars <= 0)
                    return -1; numChars <= 0 numChars 0 return -1; -1 1 return buf[curChar++]; buf[curChar++] buf curChar++ curChar public long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        } next {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        } int c = read(); c read() read while (isSpaceChar(c))
                c = read(); isSpaceChar(c) isSpaceChar c c = read() c read() read StringBuffer res = new StringBuffer(); res new StringBuffer() do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
                res.appendCodePoint(c);
                c = read();
            } res.appendCodePoint(c) res.appendCodePoint res c c = read() c read() read return res.toString(); res.toString() res.toString res private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        } isSpaceChar {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 c == '\t' c == '\r' c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 c == ' ' c ' ' c == '\n' c '\n' c == '\r' c '\r' c == '\t' c '\t' c == -1 c -1 1 int c c public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCaracalVsMonster solver = new DCaracalVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCaracalVsMonster {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long h = nl();
            TreeMap<Long, Long> tmap = new TreeMap<>();
            tmap.put(h, 1l);
            long ans = 0;
            while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            }
            pn(ans);
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCaracalVsMonster solver = new DCaracalVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCaracalVsMonster {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long h = nl();
            TreeMap<Long, Long> tmap = new TreeMap<>();
            tmap.put(h, 1l);
            long ans = 0;
            while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            }
            pn(ans);
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.Map;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCaracalVsMonster solver = new DCaracalVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCaracalVsMonster {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long h = nl();
            TreeMap<Long, Long> tmap = new TreeMap<>();
            tmap.put(h, 1l);
            long ans = 0;
            while (tmap.size() > 0) {
                if (tmap.lastKey() == 1) {
                    ans += tmap.get(tmap.lastKey());
                    break;
                }
                long x = tmap.get(tmap.lastKey());
                long which = tmap.lastKey();
                tmap.put(which / 2, tmap.getOrDefault(which / 2, 0l) + 2 * x);
                ans += x;
                tmap.remove(which);
            }
            pn(ans);
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

