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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;

public class Main {

    private static int cur, pos, sum, len;
    private static int max, min, ans, res;
    private static int ai, bi, ci, di;
    private static int[] aix, bix;
    private static int[][] aixx, bixx;
    private static long al, bl, cl, dl;
    private static long[] alx, blx;
    private static long[][] alxx, blxx;
    private static double ad, bd, cd, dd;
    private static double[] adx, bdx;
    private static double[][] adxx, bdxx;
    private static boolean ab, bb, cb, db;
    private static boolean[] abx, bbx;
    private static boolean[][] abxx, bbxx;
    private static char ac, bc, cc, dc;
    private static char[] acx, bcx;
    private static char[][] acxx, bcxx;
    private static String as, bs, cs, ds;
    private static InputReader in = new InputReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        long n = in.nextInt();
        if (n <= 100) {
            out.println(n);
        } else {
            List<Long> queue1 = new LinkedList<>();
            List<Long> queue2 = new LinkedList<>();
            List<Long> queue3;
            for (long i = 1; i < 10; i++) {
                queue1.add(i);
            }
            ans += 9;
            while (queue1.size() > 0) {
                for (Long x : queue1) {
                    for (int i = 0; i < 10; i++) {
                        al = x * 10 + i;
                        if (al <= n && check(al)) {
                            queue2.add(al);
                            ans++;
                        }
                    }
                }
                // swap
                queue3 = queue1;
                queue1 = queue2;
                queue2 = queue3;
                // clear
                queue2.clear();
            }
            out.println(ans);
        }
        out.close();
    }

    private static boolean check(long x) {
        long a = -1;
        long b = -1;
        long c;
        while (x > 0) {
            c = x % 10;
            x /= 10;
            if (a < 0) {
                a = c;
                continue;
            } else if (c == a) {
                continue;
            }

            if (b < 0) {
                b = c;
                continue;
            } else if (c == b) {
                continue;
            }
            return false;
        }

        return true;
    }

    private static class InputReader {

        private static final char MINUS = '-';
        private static final char POINT = '.';
        private static final char ZERO = '0';

        private InputStream stream;

        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

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

        public String next() {
            return readString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == MINUS) {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - ZERO;
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == MINUS) {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != POINT) {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                res *= 10;
                res += c - ZERO;
                c = read();
            }
            if (c == POINT) {
                c = read();
                double m = 1.0D;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    m /= 10;
                    res += (c - ZERO) * m;
                    c = read();
                }
            }
            return res * sgn;
        }

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

        private String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private 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++];
        }
    }
}