# E
N = int(input())
K = int(input())
import math
L = int(math.ceil(math.log10(N))) # 桁数

if K==1:
    print(9 * (L-1) + N//(1*10**(L-1)))
if K==2:
    if L==1:
        print(0)
    else:
        s = 0
        for i in range(2,L):
            s += 9*9*(i-1)
        # 全探索しちゃう
        for i in range(1,L):
            for mx in range(1,10):
                for lx in range(1,10):
                    if N >= (mx*10**(L-1) + lx*10**(i-1)):
                        s += 1
        print(s)
if K==3:
    if L<=2:
        print(0)
    else:
        s = 0
        for i in range(3,L):
            for j in range(2,i):
                s += 9*9*9*(j-1)
        for mx in range(1,10): # 先頭
            for bi in range(2,L): # おっきい方
                for bx in range(1,10):
                    for si in range(1,bi): # ちっさい方
                        if N >= (mx*10**(L-1) + 9*10**(bi-1) + bx*10**(si-1)):
                            s += 9
        print(s)