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.
#!/home/kameda/pyenv2/bin/python

power2list = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
'''
If the head of n (:(len(str(n))=i) is fixed as 'x',
number of candidates trailing digit is
9*(2^(i-1)-1)+1
9: len(range(0,10) except x)
(2^(i-1)-1): number of patterns like (xxy xyx xyy) if i=3
1: number of patterns like xxx if i=3

trailing_candidates = []
for i in range(1, 11):
    trailing_candidates.append(9*(2**(i-1)-1)+1)

'''
trailing_candidates = [1, 10, 28, 64, 136, 280, 568, 1144, 2296, 4600]
'''
For each head (1..9), trailing_candidates can be applied.
So, cumulative candidates lower than 10^i is calculated as below.

cumulative_candidates = [9]
for i in range(1, 10):
    cumulative_candidates.append(9*trailing_candidates[i]+cumulative_candidates[i-1])

'''
cumulative_candidates = [9, 99, 351, 927, 2151, 4671, 9783, 20079, 40743, 82143]

def main_y_fixed(n, y):
    #Count candidates which is n or less starting with n[0] (=x) given y (!=x)
    x = n[0]
    len_n = len(n)
    uln = 0
    if len_n == 1:
        return 1
    if int(y) > int(x):
        if int(n[1]) < int(x): # e.g. 42????? given 8 -> No candidates
            pass
        elif int(n[1]) == int(x): # e.g. 44????? given 8
            uln += main_y_fixed(n[1:], y)
        elif int(n[1]) < int(y): # e.g. 47????? given 8 -> 4488888 is the largest
            uln += power2list[len_n-2]
        elif int(n[1]) == int(y): # e.g. 48????? given 8
            uln += power2list[len_n-2]
            uln += main_y_fixed(n[1:], x)
        elif int(n[1]) > int(y): # e.g. 49????? given 8 -> 4888888 is the largest
            uln += power2list[len_n-1]
    elif int(y) == int(x):
        raise ValueError('2nd argument should be different from 1st degit of 1st argument')
    elif int(y) < int(x):
        if int(n[1]) < int(y): # e.g. 82????? given 4 -> No candidates
            pass
        elif int(n[1]) == int(y): # e.g. 84????? given 4
            uln += main_y_fixed(n[1:], x)
        elif int(n[1]) < int(y): # e.g. 87????? given 4 -> 8488888 is the largest
            uln += power2list[len_n-2]
        elif int(n[1]) == int(x): # e.g. 88????? given 4
            uln += power2list[len_n-2]
            uln += main_y_fixed(n[1:], y)
        elif int(n[1]) > int(y): # e.g. 89????? given 4 -> 8888888 is the largest
            uln += power2list[len_n-1]
    return uln

def main(n):
    #Count candidates which is n or less starting with n[0] (=x)
    x = n[0]
    len_n = len(n)
    uln = 0
    if len_n == 1:
        return 1
    if int(n[1]) > 0:
        for i in range(0, int(n[1])): #int(n[0]), ~int(n[1])-1 and all trailings
            if i != int(n[0]):
                uln += power2list[len_n-2]
            else:
                uln += trailing_candidates[len_n-2]
    if len_n == 2:
        return uln+1
    if int(n[0]) < int(n[1]):
        if int(n[2]) < int(n[0]): #e.g. 482????? -> 47777777 is the largest.
            pass
        elif int(n[2]) == int(n[0]): #e.g. 484?????
            uln += main_y_fixed(n[2:], n[1])                   
        elif int(n[2]) < int(n[1]): #e.g. 486????? -> 48488888 is the largest.
            uln += power2list[len_n-3]
        elif int(n[2]) == int(n[1]): #e.g. 488?????
            uln += power2list[len_n-3]
            uln += main_y_fixed(n[2:], n[0]) 
        elif int(n[2]) > int(n[1]): #e.g. 489?????
            uln += power2list[len_n-2]
    elif int(n[0]) == int(n[1]):
        uln += main(n[1:])
    elif int(n[0]) > int(n[1]):
        if int(n[2]) < int(n[1]): #e.g. 842????? -> 83333333 is the largest.
            pass
        elif int(n[2]) == int(n[1]): #e.g. 844?????
            uln += main_y_fixed(n[2:], n[0])          
        elif int(n[2]) < int(n[0]): #e.g. 846????? -> 84488888 is the largest.
            uln += power2list[len_n-3]
        elif int(n[2]) == int(n[0]): #e.g. 848?????
            uln += power2list[len_n-3]
            uln += main_y_fixed(n[2:], n[1]) 
        elif int(n[2]) > int(n[0]): #e.g. 849?????
            uln += power2list[len_n-2]
    return uln

if __name__ == "__main__":
    N = raw_input()
    Len_N = len(N)
    if Len_N <= 2:
        print(N)
        exit(0)
    Uln = cumulative_candidates[Len_N-2] # below 10^len_n
    Uln += (int(N[0])-1)*trailing_candidates[Len_N-1] # between 10^len_n and n[0]*10^len_n
    Uln += main(N)
    print(Uln)
    exit(0)
    
