import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

S=input()
N=int(S)
L = len(S)
K=II()
res = 0
if N <= 10000:
    for i in range(N+1):
        st = str(i)
        res += (len(st) - st.count("0")) == K
else:
    tp = int(S[:3])
    for i in range(tp+1):
        st = str(i)
        nonzeros = len(st)-st.count("0")
        # if nonzeros <= K:
        #     print("i{} non{}".format(i, nonzeros))
        if nonzeros > K:
            continue
        elif nonzeros == K:
            res += 1
            continue
        elif K-nonzeros == 1:
            res += (L-3)*9
        elif K-nonzeros == 2:
            res += 81*((L-3)*(L-4)//2)
        elif K-nonzeros == 3:
            res += 729*((L-3)*(L-4)*(L-5)//6)

print(res)
