from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
def k_1(_n):
    _n_keta = len(str(_n))
    _sub_cnt=(9*(_n_keta-1))
    _top_fig = int(str(_n)[0])
    _sub_cnt+=_top_fig
    return _sub_cnt
def k_2(_n):
    _n_keta = len(str(_n))
    _sub_cnt = 0
    for i in range(2, _n_keta):
        _sub_cnt+=(81*(i-1))
    _top_fig = int(str(_n)[0])
    zan_fig = str(_n)[1:]
    _sub_cnt+=k_1(_n)
    return _sub_cnt


    return _sub_cnt


n = int(input())
k = int(input())
n_keta = len(str(n))
sub_cnt = 0
if k == 1:
    sub_cnt+=k_1(n)
elif k == 2:
    sub_cnt+=k_2(n)

print(sub_cnt)
