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.*;
import java.util.*;

public class Bdiv2 implements Runnable {

	int n;
	HashSet<Long> set;

	private void Solution() throws IOException {
		n = nextInt();
		set = new HashSet<Long>();
		for (int a = 1; a < 10; a++)
			for (int b = 0; b < 10; b++)
				answer(a, a, b);
		print(set.size());
	}

	void answer(long cur, int a, int b) {
		if (cur > n)
			return;
		set.add(cur);
		answer(cur * 10 + a, a, b);
		answer(cur * 10 + b, a, b);
	}

	public static void main(String[] args) {
		new Bdiv2().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tokenizer;

	public void run() {
		try {
			long beginTime = System.nanoTime();
			long beginMemory = totalMemory() - freeMemory();

			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			Solution();
			out.close();

			long endTime = System.nanoTime();
			long endMemory = totalMemory() - freeMemory();

			double totalTime = (endTime - beginTime) * 1d / 1000000000;
			double totalMemory = (endMemory - beginMemory) * 1d / 1024 / 1024;

			System.err.println();
			System.err.println();
			System.err.println("Time wasted - " + totalTime / 10 + " s");
			System.err.println("Memory used - " + totalMemory + " mb");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
	}

	void halt() {
		out.close();
		System.exit(0);
	}

	long totalMemory() {
		return Runtime.getRuntime().totalMemory();
	}

	long freeMemory() {
		return Runtime.getRuntime().freeMemory();
	}

	void print(Object... o) {
		for (int i = 0; i < o.length; i++) {
			if (i != 0)
				out.print(" ");
			out.print(o[i]);
		}
	}

	void println(Object... o) {
		for (int i = 0; i < o.length; i++) {
			if (i != 0)
				out.print(" ");
			out.print(o[i]);
		}
		out.println();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	String nextLine() throws IOException {
		return in.readLine();
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(nextLine());
		return tokenizer.nextToken();
	}
}
