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

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

class TaskB {
    String digStr;
    int[] digits;
    boolean[] found;

	public void solve(int testNumber, StreamInputReader in, PrintWriter out) {
        int N = in.nextInt();
        digStr = Integer.toString(N);
        digits = new int[digStr.length()];
        for(int i = 0; i < digStr.length(); i++)
            digits[i] = digStr.charAt(i) - '0';
        found = new boolean[10000];

        long ans = 0;
        for(int x = 0; x <= 9; x++)
            for(int y = x; y <= 9; y++)
                ans += go(0, x, y, false, true, false, false, 0);

        /*for(int i = 1; i <= 123; i++)
            if(!found[i])
                out.println(i);

        out.println();*/
        out.print(ans);
	}

    private long go(int p, int x, int y, boolean greater, boolean equal, boolean usedx, boolean usedy, int debug) {
        long ret = 1;
        if(p == 0)
            ret = 0;
        if(x != y && (!usedx || !usedy))
            ret = 0;
        if(p == digits.length && greater)
            ret = 0;

        /*if(ret > 0)
            found[debug] = true;*/

        if(p < digits.length) {
            if(p > 0 || x != 0) {
                if(equal) {
                    if(x > digits[p])
                        ret += go(p + 1, x, y, true, false, true, usedy, debug * 10 + x);
                    else if(x < digits[p])
                        ret += go(p + 1, x, y, false, false, true, usedy, debug * 10 + x);
                    else
                        ret += go(p + 1, x, y, greater, true, true, usedy, debug * 10 + x);
                }
                else {
                    ret += go(p + 1, x, y,  greater, false, true, usedy, debug * 10 + x);
                }
            }

            if((p > 0 || y != 0) && x != y) {
                if(equal) {
                    if(y > digits[p])
                        ret += go(p + 1, x, y, true, false, usedx, true, debug * 10 + y);
                    else if(y < digits[p])
                        ret += go(p + 1, x, y, false, false, usedx, true, debug * 10 + y);
                    else
                        ret += go(p + 1, x, y, greater, true, usedx, true, debug * 10 + y);
                }
                else {
                    ret += go(p + 1, x, y,  greater, false, usedx, true, debug * 10 + y);
                }
            }
        }

        return ret;
    }
}

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

    public StreamInputReader(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++];
    }

    }

abstract class InputReader {

    public abstract int read();

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        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;
    }

    }

