"""
桁DPで解ける
dp[i][j][k][l] => i桁目まで見る。i桁目がjであるような数字の数。kは0でない数の個数のメモ。lは未満フラグ。
"""
N = input()
K = int(input())
dp = [[[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N))]

#初期化
x = int(N[0])
for i in range(x+1):
    if i == 0:
        dp[0][i][0][1] += 1
    else:
        if i<x:
            flag = 1
        else:
            flag = 0
        dp[0][i][1][flag] += 1

for i in range(len(N)-1):
    x = int(N[i+1])
    for j in range(10):
        for k in range(4):
            for l in range(2):
                if l:
                    r = 10
                else:
                    r = x+1
                for m in range(r):
                    if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                    if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                    dp[i+1][m][cnt][flag] += dp[i][j][k][l]

ans = 0
for j in range(10):
    ans += sum(dp[-1][j][K])

print(ans) """
桁DPで解ける
dp[i][j][k][l] => i桁目まで見る。i桁目がjであるような数字の数。kは0でない数の個数のメモ。lは未満フラグ。
""" N = input() N input() input K = int(input()) K int(input()) int input() input [[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N)) for _ in range(len(N)) _ range(len(N)) range len(N) len N for _ in range(len(N)) [[[0]*(2) for _ in range(5)]for _ in range(10)] dp = [[[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N))] dp [[[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N))] x = int(N[0]) x int(N[0]) int N[0] N 0 for i in range(x+1):
    if i == 0:
        dp[0][i][0][1] += 1
    else:
        if i<x:
            flag = 1
        else:
            flag = 0
        dp[0][i][1][flag] += 1 i range(x+1) range x+1 x 1 if i == 0:
        dp[0][i][0][1] += 1
    else:
        if i<x:
            flag = 1
        else:
            flag = 0
        dp[0][i][1][flag] += 1 i == 0 i 0 dp[0][i][0][1] += 1 dp[0][i][0][1] [0] [i] [0] dp 0 i 0 1 1 if i<x:
            flag = 1
        else:
            flag = 0
         i<x i x flag = 1 flag 1 flag = 0 flag 0 dp[0][i][1][flag] += 1 dp[0][i][1][flag] [1] [i] [0] dp 0 i 1 flag 1 for i in range(len(N)-1):
    x = int(N[i+1])
    for j in range(10):
        for k in range(4):
            for l in range(2):
                if l:
                    r = 10
                else:
                    r = x+1
                for m in range(r):
                    if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                    if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                    dp[i+1][m][cnt][flag] += dp[i][j][k][l] i range(len(N)-1) range len(N)-1 len(N) len N 1 x = int(N[i+1]) x int(N[i+1]) int N[i+1] N i+1 i 1 for j in range(10):
        for k in range(4):
            for l in range(2):
                if l:
                    r = 10
                else:
                    r = x+1
                for m in range(r):
                    if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                    if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                    dp[i+1][m][cnt][flag] += dp[i][j][k][l] j range(10) range 10 for k in range(4):
            for l in range(2):
                if l:
                    r = 10
                else:
                    r = x+1
                for m in range(r):
                    if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                    if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                    dp[i+1][m][cnt][flag] += dp[i][j][k][l] k range(4) range 4 for l in range(2):
                if l:
                    r = 10
                else:
                    r = x+1
                for m in range(r):
                    if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                    if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                    dp[i+1][m][cnt][flag] += dp[i][j][k][l] l range(2) range 2 if l:
                    r = 10
                else:
                    r = x+1
                 l r = 10 r 10 r = x+1 r x+1 x 1 for m in range(r):
                    if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                    if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                    dp[i+1][m][cnt][flag] += dp[i][j][k][l] m range(r) range r if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                     l==0 and m==x l==0 l 0 m==x m x flag = 0 flag 0 flag = 1 flag 1 if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                     m == 0 m 0 cnt = k cnt k cnt = k+1 cnt k+1 k 1 dp[i+1][m][cnt][flag] += dp[i][j][k][l] dp[i+1][m][cnt][flag] [cnt] [m] [i+1] dp i+1 i 1 m cnt flag dp[i][j][k][l] [k] [j] [i] dp i j k l ans = 0 ans 0 for j in range(10):
    ans += sum(dp[-1][j][K]) j range(10) range 10 ans += sum(dp[-1][j][K]) ans sum(dp[-1][j][K]) sum dp[-1][j][K] [j] [-1] dp -1 j K print(ans) print ans flag = 1 1 flag r = x+1 x+1 r N = input() input() N flag = 1 1 flag K = int(input()) int(input()) K x = int(N[i+1]) int(N[i+1]) x flag = 0 0 flag cnt = k+1 k+1 cnt ans += sum(dp[-1][j][K]) sum(dp[-1][j][K]) ans x = int(N[0]) int(N[0]) x ans = 0 0 ans dp = [[[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N))] [[[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N))] dp r = 10 10 r flag = 0 0 flag cnt = k k cnt
"""
桁DPで解ける
dp[i][j][k][l] => i桁目まで見る。i桁目がjであるような数字の数。kは0でない数の個数のメモ。lは未満フラグ。
"""
N = input()
K = int(input())
dp = [[[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N))]

#初期化
x = int(N[0])
for i in range(x+1):
    if i == 0:
        dp[0][i][0][1] += 1
    else:
        if i<x:
            flag = 1
        else:
            flag = 0
        dp[0][i][1][flag] += 1

for i in range(len(N)-1):
    x = int(N[i+1])
    for j in range(10):
        for k in range(4):
            for l in range(2):
                if l:
                    r = 10
                else:
                    r = x+1
                for m in range(r):
                    if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                    if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                    dp[i+1][m][cnt][flag] += dp[i][j][k][l]

ans = 0
for j in range(10):
    ans += sum(dp[-1][j][K])

print(ans)