One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.

But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.

Input

Input data contains the only number n (1 ≤ n ≤ 109).

Output

Output the only number — answer to the problem.

Examples

Input

10


Output

2

Note

For n = 10 the answer includes numbers 1 and 10.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
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;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CHexadecimalsNumbers solver = new CHexadecimalsNumbers();
        solver.solve(1, in, out);
        out.close();
    }

    static class CHexadecimalsNumbers {
        long[][] dp;

        long digitDp(int index, int sum, boolean tight, ArrayList<Integer> digits) {
            if (index == -1) return 1;
            if (!tight && dp[index][sum] != -1) return dp[index][sum];
            long ans = 0;
            int k = (tight) ? digits.get(index) : 9;
            for (int i = 0; i <= k; i++) {
                boolean new_tight = (digits.get(index) == i) ? tight : false;
                if (i == 0 || i == 1) ans += digitDp(index - 1, sum + i, new_tight, digits);
            }
            if (!tight) dp[index][sum] = ans;
            return ans;
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            dp = new long[20][18 * 10];
            for (int i = 0; i <= 18; i++) {
                Arrays.fill(dp[i], -1);
            }


            long b = in.scanLong();
            ArrayList<Integer> digitsB = getDigits(b);
            long sB = digitDp(digitsB.size() - 1, 0, true, digitsB);
            out.println(sB - 1);

        }

        ArrayList<Integer> getDigits(long x) {
            ArrayList<Integer> arrayList = new ArrayList<>();
            while (x > 0) {
                arrayList.add((int) (x % 10));
                x /= 10;
            }
            return arrayList;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

    }
}

