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.
The first line contains a single integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">9</sup>) — Polycarpus's number.
'''
给你一个数字n，找出所有小于等于n并大于0的数字中由不超过两个不同数字组成的数，例如，123，
小于等于123的数中只有102, 103, 104, 105, 106, 107, 108, 109, 120, 123是由三个不同数字组成，
其他数字都是由两个数字组成，所以答案为123-10=113
'''
n = int(input())
#print(n)
number_list = []
while n:
    number_list.append(n % 10)
    n = n // 10
#print(number_list)
number_list.reverse()
#count = 0
if len(number_list) < 3:
    print(n)
else:
    temp_list = number_list
    # 找到最小和第二小的数
    min1 = min(temp_list)
    m1_index = temp_list.index(min1)
    temp_list.pop(min1)
    min2 = min(temp_list)
    m2_index = temp_list.index(min2)
# 计算可能性
count = 0
if m1_index or m2_index:
    if not m1_index:
        count = 2*(n-2) * (min2+1) * min1
    elif not m2_index:
        count = 2*(n-2) * min2 * (min1+1)
    else:
        count = 2*(n-2) * min2 * min1 + 2*(n-3) * min2 + 2*(n-3) * min1
print(count)
		  		   	    	  					 		 		  	