N = input()
num = int(N)
K = int(input())
nl = len(N)
cnt = 0


for i in range(1,nl+1):
    if i < nl:
        if K == 1:
            cnt += 9
        elif K == 2:
            if i > 1:
                cnt += 9 * (i-1) * 9
        else:
            if i > 2:
                cnt += 9 * (i-1) * (i-2) * 9 * 9 // 2
    else:
        if K == 1:
            t = int(N[0])
            cnt += t
        elif K == 2 and i > 1:
            x = int(N[0])
            cnt += (x-1) * (i-1) * 9
            nflg = False
            for j in range(1,nl):
                nj = int(N[j])
                if nflg:
                    cnt += 9
                else:
                    cnt += nj
                if nj > 0:
                    nflg = True
        elif K == 3 and i > 2:
            x = int(N[0])
            cnt += (x-1) * (i-1) * (i-2) * 9 * 9 // 2
            ncnt = 0
            for j in range(1,nl):
                nj = int(N[j])
                #if ncnt > 1 and i-j-2 > 0:
                #   cnt += (i-j-1) * (i-j-2) * 9 * 9 // 2
                if ncnt == 1:
                    if nj > 0 :
                        ncnt += 1
                        if i-j-1 > 0:
                            cnt += (nj-1) * (i-j-1) * 9
                        elif i-j > 0:
                            cnt += nj
                elif ncnt == 0:
                    if nj > 0:
                        ncnt += 1
                        #if i-j-2 > 0:
                        #    cnt += (nj-1) * (i-j-1) * (i-j-2) * 9 * 9 // 2
                        #elif i-j-1 > 0:
                        #    cnt += (nj-1) * 9

print (cnt)
