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

def keta(n):
    number = 0
    while(n>0):
        number += 1
        n = n //10
    return number

def k1(n):
    number = keta(n)
    sum = n // (10**(number-1))
    for i in range(number - 1):
        sum += 9
    return sum

def k2(n):
    number = keta(n)
    if number < 2:
        return 0
    first_digit = n // (10**(number-1))
    second_digit = (n%(10**(number-1))) // (10**(number-2))
    #最上桁がそのままの数のとき.ex.250なら210,220,230,240,250
    sum = k1(second_digit) + (first_digit - 1) * 9
    #ex.250なら201,202,...209
    #ex.2500なら2010,...2090,2001,2002,...2009
    sum += first_digit * 9 * (number - 2)
    #上位桁を0で埋めていく場合.ex.250なら11,12,...99
    sum += 9 * 9 * (number - 1) * (number - 2) //2
    return sum

def k3(n):
    number = keta(n)
    if number < 3:
        return 0
    first_digit = n // (10**(number-1))
    #print(first_digit)
    #最上桁を除いたn
    new_n = n - first_digit * (10**(number-1))
    #print(new_n)
    #最上桁そのままの場合
    sum = k2(new_n)
    #print(sum)
    #最上桁を変化させていった場合
    sum += (first_digit - 1) * 9 * 9 * (number - 1) * (number - 2) // 2
    #print(sum)
    #上位桁を0で埋めていく場合
    sum += 9 * 9 * 9 * (number - 1) * (number - 2) * (number - 3) // 6
    #print(sum)
    return sum
    
if k == 1:
    print(k1(n))

elif k == 2:
    print(k2(n))

elif k == 3:
    print(k3(n))
    