import sys

read = sys.stdin.read


def main():
    N, K = map(int, read().split())

    dp1 = [0] * (K + 1)
    dp2 = [0] * (K + 1)
    dp1[0] = 1

    for x in map(int, str(N)):
        dp1, dp1_prev = [0] * (K + 1), dp1
        dp2, dp2_prev = [0] * (K + 1), dp2
        for j in range(K, -1, -1):
            if j > 0:
                dp2[j] = dp2_prev[j - 1] * 9
                if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
            dp2[j] += dp2_prev[j]
            if x != 0:
                dp2[j] += dp1_prev[j]
                
            if x != 0:
                if j > 0:
                    dp1[j] = dp1_prev[j - 1]
            else:
                dp1[j] = dp1_prev[j]

    print(dp1[K] + dp2[K])
    return


if __name__ == '__main__':
    main() import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read def main():
    N, K = map(int, read().split())

    dp1 = [0] * (K + 1)
    dp2 = [0] * (K + 1)
    dp1[0] = 1

    for x in map(int, str(N)):
        dp1, dp1_prev = [0] * (K + 1), dp1
        dp2, dp2_prev = [0] * (K + 1), dp2
        for j in range(K, -1, -1):
            if j > 0:
                dp2[j] = dp2_prev[j - 1] * 9
                if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
            dp2[j] += dp2_prev[j]
            if x != 0:
                dp2[j] += dp1_prev[j]
                
            if x != 0:
                if j > 0:
                    dp1[j] = dp1_prev[j - 1]
            else:
                dp1[j] = dp1_prev[j]

    print(dp1[K] + dp2[K])
    return main N, K = map(int, read().split()) N map(int, read().split()) map int read().split() ().split () read split K dp1 = [0] * (K + 1) dp1 [0] * (K + 1) [0] 0 K + 1 K 1 dp2 = [0] * (K + 1) dp2 [0] * (K + 1) [0] 0 K + 1 K 1 dp1[0] = 1 dp1[0] dp1 0 1 for x in map(int, str(N)):
        dp1, dp1_prev = [0] * (K + 1), dp1
        dp2, dp2_prev = [0] * (K + 1), dp2
        for j in range(K, -1, -1):
            if j > 0:
                dp2[j] = dp2_prev[j - 1] * 9
                if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
            dp2[j] += dp2_prev[j]
            if x != 0:
                dp2[j] += dp1_prev[j]
                
            if x != 0:
                if j > 0:
                    dp1[j] = dp1_prev[j - 1]
            else:
                dp1[j] = dp1_prev[j]

     x map(int, str(N)) map int str(N) str N dp1, dp1_prev = [0] * (K + 1), dp1 dp1 [0] * (K + 1) [0] 0 K + 1 K 1 dp1_prev dp1 dp2, dp2_prev = [0] * (K + 1), dp2 dp2 [0] * (K + 1) [0] 0 K + 1 K 1 dp2_prev dp2 for j in range(K, -1, -1):
            if j > 0:
                dp2[j] = dp2_prev[j - 1] * 9
                if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
            dp2[j] += dp2_prev[j]
            if x != 0:
                dp2[j] += dp1_prev[j]
                
            if x != 0:
                if j > 0:
                    dp1[j] = dp1_prev[j - 1]
            else:
                dp1[j] = dp1_prev[j]

     j range(K, -1, -1) range K -1 -1 if j > 0:
                dp2[j] = dp2_prev[j - 1] * 9
                if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
             j > 0 j 0 dp2[j] = dp2_prev[j - 1] * 9 dp2[j] dp2 j dp2_prev[j - 1] * 9 dp2_prev[j - 1] dp2_prev j - 1 j 1 9 if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
             x != 0 x 0 dp2[j] += dp1_prev[j - 1] * (x - 1) dp2[j] dp2 j dp1_prev[j - 1] * (x - 1) dp1_prev[j - 1] dp1_prev j - 1 j 1 x - 1 x 1 dp2[j] += dp2_prev[j] dp2[j] dp2 j dp2_prev[j] dp2_prev j if x != 0:
                dp2[j] += dp1_prev[j]
                
             x != 0 x 0 dp2[j] += dp1_prev[j] dp2[j] dp2 j dp1_prev[j] dp1_prev j if x != 0:
                if j > 0:
                    dp1[j] = dp1_prev[j - 1]
            else:
                dp1[j] = dp1_prev[j]

     x != 0 x 0 if j > 0:
                    dp1[j] = dp1_prev[j - 1]
             j > 0 j 0 dp1[j] = dp1_prev[j - 1] dp1[j] dp1 j dp1_prev[j - 1] dp1_prev j - 1 j 1 dp1[j] = dp1_prev[j] dp1[j] dp1 j dp1_prev[j] dp1_prev j print(dp1[K] + dp2[K]) print dp1[K] + dp2[K] dp1[K] dp1 K dp2[K] dp2 K return if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N, K = map(int, read().split())

    dp1 = [0] * (K + 1)
    dp2 = [0] * (K + 1)
    dp1[0] = 1

    for x in map(int, str(N)):
        dp1, dp1_prev = [0] * (K + 1), dp1
        dp2, dp2_prev = [0] * (K + 1), dp2
        for j in range(K, -1, -1):
            if j > 0:
                dp2[j] = dp2_prev[j - 1] * 9
                if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
            dp2[j] += dp2_prev[j]
            if x != 0:
                dp2[j] += dp1_prev[j]
                
            if x != 0:
                if j > 0:
                    dp1[j] = dp1_prev[j - 1]
            else:
                dp1[j] = dp1_prev[j]

    print(dp1[K] + dp2[K])
    return def main():
    N, K = map(int, read().split())

    dp1 = [0] * (K + 1)
    dp2 = [0] * (K + 1)
    dp1[0] = 1

    for x in map(int, str(N)):
        dp1, dp1_prev = [0] * (K + 1), dp1
        dp2, dp2_prev = [0] * (K + 1), dp2
        for j in range(K, -1, -1):
            if j > 0:
                dp2[j] = dp2_prev[j - 1] * 9
                if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
            dp2[j] += dp2_prev[j]
            if x != 0:
                dp2[j] += dp1_prev[j]
                
            if x != 0:
                if j > 0:
                    dp1[j] = dp1_prev[j - 1]
            else:
                dp1[j] = dp1_prev[j]

    print(dp1[K] + dp2[K])
    return main read = sys.stdin.read sys.stdin.read read
import sys

read = sys.stdin.read


def main():
    N, K = map(int, read().split())

    dp1 = [0] * (K + 1)
    dp2 = [0] * (K + 1)
    dp1[0] = 1

    for x in map(int, str(N)):
        dp1, dp1_prev = [0] * (K + 1), dp1
        dp2, dp2_prev = [0] * (K + 1), dp2
        for j in range(K, -1, -1):
            if j > 0:
                dp2[j] = dp2_prev[j - 1] * 9
                if x != 0:
                    dp2[j] += dp1_prev[j - 1] * (x - 1)
            dp2[j] += dp2_prev[j]
            if x != 0:
                dp2[j] += dp1_prev[j]
                
            if x != 0:
                if j > 0:
                    dp1[j] = dp1_prev[j - 1]
            else:
                dp1[j] = dp1_prev[j]

    print(dp1[K] + dp2[K])
    return


if __name__ == '__main__':
    main()
