N = input()
n = len(N)
K = int(input())
ans = 0
if K == 1:
    for i in range(n):
        a = int(N[i])
        if i == 0:
            ans+=a
        else:
            ans+=9
    if ans <=0:
        ans = 0
    print(ans)
    exit()
if K == 2:
    for i in range(n-1):
        for j in range(i+1,n):
            a = int(N[i])
            b = int(N[j])
            if i == 0:
                if j == 1:
                    ans+= b + (a-1) * 9
                elif int(N[j-1])==0:
                    ans+= b + (a-1)*9
                else:
                    ans+=a * 9
            else:
                ans += 9**2
    if ans <=0:
        ans=0
    print(ans)
    exit()
if K == 3:
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                a = int(N[i])
                b = int(N[j])
                c = int(N[k])
                if i == 0:
                    if j ==1:
                        ans += (b-1) * 9 + c + (a-1) * 9 * 9
                    elif int(N[j-1]) == 0:
                        ans += (b-1) * 9 + c + (a-1) * 9 * 9
                    else:
                        ans+=a * 9 * 9
                else:
                    ans += 9*9*9
    if ans<=0:
        ans=0
    print(ans)
    exit()