s = raw_input()
k = int(raw_input())
want = int(s)
ret = dict()
for a in xrange(len(s)):
    for b in xrange(a):
        for c in xrange(b):
            for d in xrange(10):
                for e in xrange(10):
                    for f in xrange(10):
                        num = 0
                        if d:
                            num += 1
                        if e:
                            num += 1
                        if f:
                            num += 1
                        if num != k:
                            continue
                        cand = (10**a) * d
                        cand += (10**b) * e
                        cand += (10**c) * f
                        if cand and cand <= want:
                            ret[cand] = True
print len(ret)
