from operator import mul
from functools import reduce

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

n = int(input())
k = int(input())
sn = str(n)
keta = len(sn)
if k > keta:
    print(0)
    exit()

def one(sn, keta):
    result = 0
    
    result = (keta-1)*9
    for i in range(1, int(sn[0])+1):
        if '0' in str(i):
            continue
        if len(str(i)) != 1:
            continue
        result += 1
    return result

def two(sn, keta):
    result = 0
    
    mult = keta - 2
    if mult < 0:
        pass
    else:
        for m in range(1, mult+1):
            result += m*9*9

    for i in range(1, int(sn[0])+1):
        result += (keta-2)*9
        
        if i < int(sn[0]):
            result += 9
        else:
            for _ in range(int(sn[1])):
                result += 1
    return result

def three(sn, keta):
    result = 0
    
    mult = keta - 3
    if mult < 0:
        pass
    else:
        for m in range(1, mult+1):
            result += cmb(m+1, 2)*9*9*9

    for i in range(1, int(sn[0])+1):
        if i != int(sn[0]):
            result += cmb(keta-1, 2)*9*9
        else:
            for j in range(1, int(sn[1])+1):
                if j != int(sn[1]):
                    result += (keta-2)*9
                else:
                    result += (keta-3)*9
                    result += int(sn[2])
        
    return result

if k==1:
    print(one(sn, keta))
elif k==2:
    print(two(sn, keta))
else:
    print(three(sn, keta))