

#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def com(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))



def main():
    s = list(input())
    n = len(s)
    k = ii()
    ans = 0

    if n == k:
        for i in range(n):
            ans+= pow(9,k-i-1)*(int(s[i])-1)
        ans+=1
        print(ans)
        exit()




    for i in range(k):
        tmp = int(s[i])
        if i == 0:
            ans+=(9**k)*com(n-1,k)
 #           print(n-1,k-1)
            ans+=(9**(k-1))*com(n-1,k-1)*(tmp-1)
 #           print(i,ans)
        else:
            ans+=(9**(k-i))*com(n-1-i,k-i)
            if tmp > 0:
                ans+=(9**(k-i-1))*com(n-1-i,k-i-1)*(tmp-1)
#            print(i,ans)
    ans+=1
    print(ans)





main()
