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


public class Main {
/*



 */
	public static void main(String[] args) throws Exception {
		uu.s1();
		uu.out.close();
	}
	public static class uu {
		public static BR in = new BR();
		public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		public static boolean bg = true;
		public static void s1() throws Exception {
			long n1 = in.ni();
			
			IntSet s1 = new IntSet();
			for (int x = 0; x <= 9; x++){
				for (int y = x+1; y <= 9; y++){
					for (int k = 1; k <= 10; k++){
						int v1 = k;
						int[] l1 = new int[v1];
						for (;;){
							long fin = 0;
							for (int qq = 0; qq < v1; qq++){
								long cur = 0;
								if (l1[qq] == 1){
									cur = y;
								}
								else {
									cur = x;
								}
								fin*= 10l;
								fin += cur;
							}
							
							if (fin <= n1){
								s1.add((int)fin);
							}
							int ptr = l1.length-1;
							boolean ex = false;
							for (;;){
								if (ptr == -1){
									ex = true;
									break;
								}
								if (l1[ptr] == 0){
									l1[ptr] = 1;
									break;
								}
								else {
									l1[ptr] = 0;
									ptr--;
								}
							}
							if (ex) break;
						}
					}
					
				}
			}
			s1.remove(0);
			pn(s1.size);
		}
		
		public static void s2() throws Exception {
			
		}
		public static void s3() throws Exception {
			
		}
		
		private static void pn(Object... o1) {
			for (int i = 0; i < o1.length; i++){
				if (i!= 0) out.print(" ");
				out.print(o1[i]);
			}
			out.println();
		}

		public static boolean allTrue(boolean ... l1){
			for (boolean e: l1) if (!e) return false;
			return true;
		}
		public static boolean allFalse(boolean ... l1){
			for (boolean e: l1) if (e) return false;
			return true;
		}
	}
	private static class IntSet {
		public static int hash(int h) {
			h ^= (h >>> 20) ^ (h >>> 12);
			return h ^ (h >>> 7) ^ (h >>> 4);
		}
		
		public boolean[] used = null;
		public int[] key = null;
		public double factor = 0.7;
		public int size = 0;
		public int init = 16;
		public IntSet(){
			used  = new boolean[init];
			key = new int[init];
		}
		public void rehash(){
			int newlen = (key.length<<1)+1;
			boolean[] oldused = used;
			int[] oldkey = key;
			used = new boolean[newlen];
			key = new int[newlen];
			size = 0;
			for (int i = 0; i < oldused.length; i++){
				if (oldused[i]){
					add(oldkey[i]);
				}
			}
		}
		public int idx(int key1){
			int id = hash(key1);
			if (id < 0) id *= -1;
			id %= key.length;
			for (int i = 0; ; i++){
				int add = i*i;
				if (add < 0) add *= -1;
				id += add;
				id %= key.length;
				if (used[id]){
					if (key[id] == key1){
						return id;
					}
				}
				else {
					return id;
				}
			}
		}
		
		public void add(int key1){
			int id = idx(key1);
			if (!used[id]){
				used[id] = true;
				key[id] = key1;
				size++;
			}
			if (size >= factor * key.length){
				rehash();
			}
		}
		public void remove(int key1){
			int id = idx(key1);
			if (used[id]){
				used[id] = false;
				size--;
			}
		}
	}
	private static class BR {
		BufferedReader k1 = null;
		StringTokenizer k2 = null;

		public BR() {
			k1 = new BufferedReader(new InputStreamReader(System.in));
		}
		public String nx() throws Exception {
			for (;;) {
				if (k2 == null || !k2.hasMoreTokens()) {
					String temp = k1.readLine();
					if (temp == null)
						return null;
					k2 = new StringTokenizer(temp);
				}
				else
					break;
			}

			return k2.nextToken();
		}

		public int ni() throws Exception {
			return Integer.parseInt(nx());
		}
	}
}
