n=int(input())
k=int(input())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r<0:return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if k==1:
    syo = int(str(n)[0])
    ans = 9*(len(str(n))-1)+syo
if k==2:
    fir = int(str(n)[0])
    sec = int(str(n)[1])
    ans = 9**2*cmb(len(str(n))-1,2)
    ans+=(fir-1)*9+sec
    ans += 9*cmb(len(str(n))-2,1)*fir

if k==3:
    fir = int(str(n)[0])
    sec = int(str(n)[1])
    thi = int(str(n)[2])
    ans = 9**3*cmb(len(str(n))-1,3)
    ans += (fir-1)*81+(sec-1)*9+thi
    ans += 9*9*cmb(len(str(n))-2,2)*fir
    ans += ((fir-1)*9+sec)*9*cmb(len(str(n))-3,1)

print(ans)
