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 static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        try {
            if (new File("input.txt").exists())
                System.setIn(new FileInputStream("input.txt"));
        } catch (SecurityException e) {
        }
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");
    HashSet<Long> hs = new HashSet<Long>();

    
    
    
    
    
    private void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        long n = nextLong();
        ArrayList<Long> mas = new ArrayList<Long>();
        
        int p = 1<<9;
        
        
        long dpow[] = new long[15];
        dpow[0] = 1;
        
        for(int i = 1;i < 13;i++){
            dpow[i]=dpow[i-1]*10;
        }
        
        
        int megacnt = 0;
        for(int x = 0;x<=9;x++){
            for(int y = 0;y<=9;y++){
                for(long mask = 1;mask<=p;mask++){
                    int bitcnt = 0;
                    int anti = 0;
                    long  ex = mask;
                
                
                        
                        long num = 0;
                    
                boolean flag = true;
                        int cnt = 0;
                        while(ex!=0){
                            
                            if(ex%2==0){
                                num+=(long)x*dpow[cnt];
                                //num2+=(long)7*dpow[cnt];
                            }
                            else{
                                num+=(long)y*dpow[cnt];
                                //num2+=(long)4*dpow[cnt];;
                            }
                        
                            
                            ex>>=1;
                            cnt++;
                        }
                    
                        if(num<=n && flag){ 
                            if(!hs.contains(num)){
                            megacnt++;
                            hs.add(num);
                            //out.println(num);
                            }
                        //out.println(num);
                        //mas.add(num);
                    //  mas.add(num2);
                        }
                    
                }
            }
        }
    
        /*for (long a : hs) {
            out.println(a);
        }*/
        
    
        out.println(megacnt-1);
        
    
        
        
        in.close();
        out.close();
    }

    void chk(boolean b) {
        if (b)
            return;
        System.out.println(new Error().getStackTrace()[1]);
        exit(999);
    }
    void deb(String fmt, Object... args) {
        System.out.printf(Locale.US, fmt + "%n", args);
    }
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}
