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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Template implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws FileNotFoundException {
		try {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}
	}

	class GraphBuilder {
		int n, m;
		int[] x, y;
		int index;
		int[] size;

		GraphBuilder(int n, int m) {
			this.n = n;
			this.m = m;
			x = new int[m];
			y = new int[m];
			size = new int[n];
		}

		void add(int u, int v) {
			x[index] = u;
			y[index] = v;
			size[u]++;
			size[v]++;
			index++;
		}

		void addDir(int u, int v) {
			x[index] = u;
			y[index] = v;
			size[u]++;
			index++;
		}

		int[][] buildDir() {
			int[][] graph = new int[n][];
			for (int i = 0; i < n; i++) {
				graph[i] = new int[size[i]];
			}
			for (int i = m - 1; i >= 0; i--) {
				graph[x[i]][--size[x[i]]] = y[i];
			}
			return graph;
		}

		int[][] build() {
			int[][] graph = new int[n][];
			for (int i = 0; i < n; i++) {
				graph[i] = new int[size[i]];
			}
			for (int i = m - 1; i >= 0; i--) {
				graph[x[i]][--size[x[i]]] = y[i];
				graph[y[i]][--size[y[i]]] = x[i];
			}
			return graph;
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			try {
				tok = new StringTokenizer(in.readLine());
			} catch (Exception e) {
				return null;
			}
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	int[] readIntArray(int size) throws IOException {
		int[] res = new int[size];
		for (int i = 0; i < size; i++) {
			res[i] = readInt();
		}
		return res;
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	<T> List<T>[] createGraphList(int size) {
		List<T>[] list = new List[size];
		for (int i = 0; i < size; i++) {
			list[i] = new ArrayList<>();
		}
		return list;
	}

	public static void main(String[] args) {
		new Template().run();
		// new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
	}

	long timeBegin, timeEnd;

	void time() {
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
	}

	public void run() {
		try {
			timeBegin = System.currentTimeMillis();
			memoryTotal = Runtime.getRuntime().freeMemory();
			init();
			solve();
			out.close();
			if (System.getProperty("ONLINE_JUDGE") == null) {
				time();
				memory();
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}
	
	TreeSet<Long> gen(long a, long b, long limit) {
		TreeSet<Long> all = new TreeSet<>();
		all.add(0L);
		while (true) {
			int wasSize = all.size();
			List<Long> add = new ArrayList<>();
			for (long x : all) {
				add.add(x * 10 + a);
				add.add(x * 10 + b);
			}
			for (long x : add) {
				if (x <= limit) all.add(x);
			}
			if (wasSize == all.size()) break;
		}
		return all;
	}


	void solve() throws IOException {		
		int n = readInt();
		TreeSet<Long> set = new TreeSet<>();
		for (int x=0;x<10;x++) {
			for (int y =0;y<10;y++) {
				set.addAll(gen(x, y, n));
			}
		}
		set.remove(0L);
		out.println(set.size());
	}

}