N=9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
K=3
import math
ans=0
n=str(N)
a=len(n)
def combi(p,q):
    return math.factorial(p)//(math.factorial(q)*math.factorial(p-q))
def mi(i):
    if int(n[i])==0:
        return 0
    else:
        return int(n[i])-1


if a<K:
    ans=0
else:
    if a>K:
        ans+=combi(a-1,K)*(9**K)
    if K==1:ans+=int(n[0])
    elif K==2:ans+=mi(0)*(a-1)*9+(a-2)*9+int(n[1])
    elif a==3 : ans+=mi(0)*81*(combi(a-1,2))+9*mi(1)+int(n[2])
    else:ans+=mi(0)*81*(combi(a-1,2))+combi(a-2,2)*81+9*(a-2)*mi(1)+int(n[2])+(a-3)*9

print(ans)