n=int(input())
k=int(input())


if k==1:
    icnt=0
    for i in range(0,99):
        for i1 in range(1,10):
            x=i1*10**i
            if x<=n:
                icnt=icnt+1
    print(icnt)
elif k==2:
    icnt=0
    for i in range(0,99):
        for j in range(i+1,99):
            for i1 in range(1,10):
                for j1 in range(1,10):
                    x=i1*10**i+j1*10**j
                    if x<=n:
                        icnt=icnt+1
    print(icnt)
elif k==3:
    icnt=0
    for i in range(0,99):
        for j in range(i+1,99):
            for m in range(j+1,99):
                for i1 in range(1,10):
                    for j1 in range(1,10):
                        for m1 in range(1,10):
                            x=i1*10**i+j1*10**j+m1*10**m
                            if x<=n:
                                icnt=icnt+1
    print(icnt)
            