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.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *cf244b_uln
 * @author zulkan
 */
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import static java.lang.System.*;
import java.math.BigInteger;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class cf244b_uln {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static Scanner sc = new Scanner(System.in);

    public static String getString() {
        try {
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }

    public static Integer getInt() {
        try {
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }

    public static Integer[] getIntArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Integer temp2[] = new Integer[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Integer.parseInt(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static int getMax(Integer[] ar) {
        int t = ar[0];
        for (int i = 0; i < ar.length; i++) {
            if (ar[i] > t) {
                t = ar[i];
            }
        }
        return t;
    }

    public static void print(Object a) {
        out.println(a);
    }

    public static int nextInt() {
        return sc.nextInt();
    }

    public static double nextDouble() {
        return sc.nextDouble();
    }

    public static BigInteger getFact(long in) {
        BigInteger ot = new BigInteger("1");
        for (Integer i = 1; i <= in; i++) {
            ot = ot.multiply(new BigInteger(i.toString()));
        }
        return ot;
    }

    public static String gbase(int a, int base) {
        StringBuilder out = new StringBuilder();
        int temp = a;
        while (temp > 0) {
            //out = temp % base + out;
            out.insert(0, temp % base);
            temp /= base;
        }
        return out.toString();
    }

    public static void main(String[] ar) {



        int n = getInt();
        int out = 0;

        if (n <= 100) {
            print(n);
            return;
        }

        //boolean all[] = new boolean[Integer.MAX_VALUE];
        HashSet<Long> all = new HashSet<Long>();


        for (Long i = 0l; i < 10; i += 1) {
            for (Long j = i; j < 10; j++) {
                if (i != 0 || j != 0) {
                    ArrayList<Long> last = new ArrayList<Long>();
                    last.add(i);
                    last.add(j);

                    //all[i.intValue()] = true;
                    //all[j.intValue()] = true;


                    
                    all.add(i);
                    all.add(j);

                    Long ls = j;
                    while (ls < n) {
                        ArrayList<Long> last2 = new ArrayList<Long>();
                        for (int ii = 0; ii < last.size(); ii++) {
                            Long a = last.get(ii) * 10 + i;
                            Long b = last.get(ii) * 10 + j;
                            last2.add(a);
                            last2.add(b);
                            //print(a + " " + b);
                            //if (b <= n) {
                            //all[b.intValue()] = true;
                            all.add(b);
                            // }
                            // if (a <= n) {
                            all.add(a);
                            //all[a.intValue()] = true;
                            // }
                            ls = b;
                        }
                        // print(ls + " " + last2);
                        last = last2;

                    }

                }
            }
        }
        /*
        for (Integer i = 1; i <= n; i++) {
            //print(i + " " + all[i]);
            if (all[i]) {
                out++;
            }
        }
         * 
         */
        all.remove(0l);
        for(Long i : all){
            if(i<=n){
                out++;
            }
        }
        print(out);


    }
}
