Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.

Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 ≤ x, y ≤ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.

Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.

Input

The first line contains a single integer n (1 ≤ n ≤ 109) — Polycarpus's number.

Output

Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.

Examples

Input

10


Output

10


Input

123


Output

113

Note

In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.

In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
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;
        inclass in = new inclass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BUndoubtedlyLuckyNumbers solver = new BUndoubtedlyLuckyNumbers();
        solver.solve(1, in, out);
        out.close();
    }

    static class BUndoubtedlyLuckyNumbers {
        public void solve(int testNumber, inclass in, PrintWriter out) {
            int n = in.nextInt();
            TreeSet<String> fake = new TreeSet<>();
            for (int i = 0; i < Math.pow(2, 10); i++) {
                String str = Long.toBinaryString(i);
                fake.add(str);
            }
            TreeSet<Long> set = new TreeSet<>();
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    for (String el : fake) {
                        String str = "" + el;
                        int vis[] = new int[str.length()];
                        String temp1 = "";
                        for (int k = 0; k < str.length(); k++) {
                            if (str.charAt(k) == '0') {
                                vis[k] = 1;
                                temp1 += (char) (i + '0');
                            } else {
                                temp1 += str.charAt(k);
                            }
                        }
                        String temp2 = "";
                        for (int k = 0; k < temp1.length(); k++) {
                            if (vis[k] == 0 && temp1.charAt(k) == '1') {
                                temp2 += (char) (j + '0');
                            } else {
                                temp2 += temp1.charAt(k);
                            }
                        }
                        set.add(Long.parseLong(temp2));
                    }
                }
            }
            set.remove(0l);
            out.println(set.headSet((long) n, true).size());
        }

    }

    static class inclass {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private inclass.SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

