def main():
    n_str = input()
    k = int(input())
    keta = len(n_str)

    def k1():
        ans = keta*9 - (9-int(n_str[0]))
        print(ans)

    def k2():
        if keta <= 2 and int(n_str) <= 10:
            print(0)
            return

        ans = (
            (keta*(keta-1)//2) * 9**2
            - (9-int(n_str[0])) * (keta-1) * 9
            - (9-int(n_str[1]))
        )

        for i in range(1, keta):
            if n_str[i] != 0:
                break
            else:
                ans -= (9-int(n_str[i]))

        print(ans)

    def k3():
        if keta <= 3 and int(n_str) <= 110:
            print(0)
            return

        ans = (
            (keta*(keta-1)*(keta-2)//6) * 9**3
            - (9-int(n_str[0])) * ((keta-1)*(keta-2)//2) * 9**2
            - (9-int(n_str[1])) * (keta-2) * 9
            - (9-int(n_str[2]))
        )
        print(ans)

    if k == 1:
        k1()
    elif k == 2:
        k2()
    else:
        k3()


if __name__ == '__main__':
    main()
