import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n = s_in()
k = n_in()

res = 0
d = len(n)

def comb(a,b):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b == 2:
        return a*(a-1)//2
    if b == 3:
        return (a)*(a-1)*(a-2)//6

    return 0
    

# 手前まで完全一致でii桁以降でl回非ゼロの時の場合の数
def calc(i, l):
    m = int(n[i])

    if i == d-1:
        if l == 0:
            if m == 0:
                return 1
            else:
                return 0
        elif l == 1:
            if m == 0:
                return 0
            else:
                return m
        else:
            return 0
            
        
    if m == 0:
        return calc(i+1, l)
    else:
        tmp = calc(i+1, l-1) # i桁めがmの場合
        tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) # 1..(m-1)
        tmp += comb(d-i-1,l)*int(9**l)

        return tmp

print(calc(0,k))
 import sys sys sys.setrecursionlimit(700000) sys.setrecursionlimit sys setrecursionlimit 700000 def s_in():
    return input() s_in return input() input() input def n_in():
    return int(input()) n_in return int(input()) int(input()) int input() input def l_in():
    return list(map(int, input().split())) l_in return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def print_l(l):
    print(' '.join(map(str, l))) print_l print(' '.join(map(str, l))) print ' '.join(map(str, l)) ' '.join ' ' join map(str, l) map str l l l class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res Interval def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

     __init__ self.li = li self.li self li li self.n = len(li) self.n self n len(li) len li self.sum_li = [li[0]] self.sum_li self sum_li [li[0]] li[0] li 0 for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

     i range(1, self.n) range 1 self.n self n self.sum_li.append(self.sum_li[i-1] + li[i]) self.sum_li.append self.sum_li self sum_li append self.sum_li[i-1] + li[i] self.sum_li[i-1] self.sum_li self sum_li i-1 i 1 li[i] li i self self li li def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res sum if b is None:
            return self.sum(0, a)

         b is None b None return self.sum(0, a) self.sum(0, a) self.sum self sum 0 a res = self.sum_li[min(self.n-1, b-1)] res self.sum_li[min(self.n-1, b-1)] self.sum_li self sum_li min(self.n-1, b-1) min self.n-1 self.n self n 1 b-1 b 1 if a > 0:
            res -= self.sum_li[a-1]
         a > 0 a 0 res -= self.sum_li[a-1] res self.sum_li[a-1] self.sum_li self sum_li a-1 a 1 return res res self self a a b=None b None n = s_in() n s_in() s_in k = n_in() k n_in() n_in res = 0 res 0 d = len(n) d len(n) len n def comb(a,b):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b == 2:
        return a*(a-1)//2
    if b == 3:
        return (a)*(a-1)*(a-2)//6

    return 0
    

# 手前まで完全一致でii桁以降でl回非ゼロの時の場合の数 comb if b == 0:
        return 1
     b == 0 b 0 return 1 1 if b == 1:
        return a
     b == 1 b 1 return a a if b == 2:
        return a*(a-1)//2
     b == 2 b 2 return a*(a-1)//2 a*(a-1)//2 a*(a-1) a a-1 a 1 2 if b == 3:
        return (a)*(a-1)*(a-2)//6

     b == 3 b 3 return (a)*(a-1)*(a-2)//6 (a)*(a-1)*(a-2)//6 (a)*(a-1)*(a-2) (a)*(a-1) a a-1 a 1 a-2 a 2 6 return 0 0 a a b b def calc(i, l):
    m = int(n[i])

    if i == d-1:
        if l == 0:
            if m == 0:
                return 1
            else:
                return 0
        elif l == 1:
            if m == 0:
                return 0
            else:
                return m
        else:
            return 0
            
        
    if m == 0:
        return calc(i+1, l)
    else:
        tmp = calc(i+1, l-1) # i桁めがmの場合
        tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) # 1..(m-1)
        tmp += comb(d-i-1,l)*int(9**l)

        return tmp calc m = int(n[i]) m int(n[i]) int n[i] n i if i == d-1:
        if l == 0:
            if m == 0:
                return 1
            else:
                return 0
        elif l == 1:
            if m == 0:
                return 0
            else:
                return m
        else:
            return 0
            
        
     i == d-1 i d-1 d 1 if l == 0:
            if m == 0:
                return 1
            else:
                return 0
        elif l == 1:
            if m == 0:
                return 0
            else:
                return m
        else:
            return 0
            
        
     l == 0 l 0 if m == 0:
                return 1
            else:
                return 0
         m == 0 m 0 return 1 1 return 0 0 elif l == 1:
            if m == 0:
                return 0
            else:
                return m
         l == 1 l 1 if m == 0:
                return 0
            else:
                return m
         m == 0 m 0 return 0 0 return m m return 0 0 if m == 0:
        return calc(i+1, l)
    else:
        tmp = calc(i+1, l-1) # i桁めがmの場合
        tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) # 1..(m-1)
        tmp += comb(d-i-1,l)*int(9**l)

        return tmp m == 0 m 0 return calc(i+1, l) calc(i+1, l) calc i+1 i 1 l tmp = calc(i+1, l-1) tmp calc(i+1, l-1) calc i+1 i 1 l-1 l 1 tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) tmp (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) (m-1)*comb(d-i-1, l-1) m-1 m 1 comb(d-i-1, l-1) comb d-i-1 d-i d i 1 l-1 l 1 int(9**(l-1)) int 9**(l-1) 9 l-1 l 1 tmp += comb(d-i-1,l)*int(9**l) tmp comb(d-i-1,l)*int(9**l) comb(d-i-1,l) comb d-i-1 d-i d i 1 l int(9**l) int 9**l 9 l return tmp tmp i i l l print(calc(0,k)) print calc(0,k) calc 0 k res = 0 0 res def calc(i, l):
    m = int(n[i])

    if i == d-1:
        if l == 0:
            if m == 0:
                return 1
            else:
                return 0
        elif l == 1:
            if m == 0:
                return 0
            else:
                return m
        else:
            return 0
            
        
    if m == 0:
        return calc(i+1, l)
    else:
        tmp = calc(i+1, l-1) # i桁めがmの場合
        tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) # 1..(m-1)
        tmp += comb(d-i-1,l)*int(9**l)

        return tmp def calc(i, l):
    m = int(n[i])

    if i == d-1:
        if l == 0:
            if m == 0:
                return 1
            else:
                return 0
        elif l == 1:
            if m == 0:
                return 0
            else:
                return m
        else:
            return 0
            
        
    if m == 0:
        return calc(i+1, l)
    else:
        tmp = calc(i+1, l-1) # i桁めがmの場合
        tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) # 1..(m-1)
        tmp += comb(d-i-1,l)*int(9**l)

        return tmp calc def s_in():
    return input() def s_in():
    return input() s_in def n_in():
    return int(input()) def n_in():
    return int(input()) n_in class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res Interval k = n_in() n_in() k d = len(n) len(n) d def comb(a,b):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b == 2:
        return a*(a-1)//2
    if b == 3:
        return (a)*(a-1)*(a-2)//6

    return 0
    

# 手前まで完全一致でii桁以降でl回非ゼロの時の場合の数 def comb(a,b):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b == 2:
        return a*(a-1)//2
    if b == 3:
        return (a)*(a-1)*(a-2)//6

    return 0
    

# 手前まで完全一致でii桁以降でl回非ゼロの時の場合の数 comb n = s_in() s_in() n def l_in():
    return list(map(int, input().split())) def l_in():
    return list(map(int, input().split())) l_in def print_l(l):
    print(' '.join(map(str, l))) def print_l(l):
    print(' '.join(map(str, l))) print_l
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n = s_in()
k = n_in()

res = 0
d = len(n)

def comb(a,b):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b == 2:
        return a*(a-1)//2
    if b == 3:
        return (a)*(a-1)*(a-2)//6

    return 0
    

# 手前まで完全一致でii桁以降でl回非ゼロの時の場合の数
def calc(i, l):
    m = int(n[i])

    if i == d-1:
        if l == 0:
            if m == 0:
                return 1
            else:
                return 0
        elif l == 1:
            if m == 0:
                return 0
            else:
                return m
        else:
            return 0
            
        
    if m == 0:
        return calc(i+1, l)
    else:
        tmp = calc(i+1, l-1) # i桁めがmの場合
        tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) # 1..(m-1)
        tmp += comb(d-i-1,l)*int(9**l)

        return tmp

print(calc(0,k))

