#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    char N[102];
    int K;
    int l;
    int nonZeroN[3] = {1000, 1000, 1000};
    int nonZeroRank[3] = {1000, 1000, 1000};
    int nonZeroCount = 0;
    int rank = 0;
    ll ans = 0;

    //input
    cin >> N;
    l = strlen(N);
    for(int i = 0; i < l; i++){
        if(N[i] != '0'){
            nonZeroN[nonZeroCount] = i;
            nonZeroRank[nonZeroCount] = l - i;
            nonZeroCount++;
        }
        if(nonZeroCount > 3){
            break;
        }
    }

    cin >> K;

    if(K == 1){
        ans += 9 * (nonZeroRank[0] - 1);
        ans += (int)N[nonZeroN[0]] - 48;
    }else if(K == 2){
        ans += 9 * 9 * (nonZeroRank[0] - 1) * (nonZeroRank[0] - 2) / 2;
        for(int i = 1; i < (int)N[nonZeroN[0]] - 48; i++){
            ans += 9 * (nonZeroRank[0] - 1);
        }
        if(nonZeroRank[1] != 1000){
            ans += 9 * (nonZeroRank[1] - 1);
            ans += (int)N[nonZeroN[1]] - 48;
        }
    }else{
        ans += 9 * 9 * 9 * (nonZeroRank[0] - 1) * (nonZeroRank[0] - 2) * (nonZeroRank[0] - 3) / 6;
        for(int i = 1; i < (int)N[nonZeroN[0]] - 48; i++){
            ans += 9 * 9 * (nonZeroRank[0] - 1) * (nonZeroRank[0] - 2) / 2;
        }
        if(nonZeroRank[1] != 1000){
            ans += 9 * 9 * (nonZeroRank[1] - 1) * (nonZeroRank[1] - 2) / 2;
            for(int i = 1; i < (int)N[nonZeroN[1]] - 48; i++){
                ans += 9 * (nonZeroRank[1] - 1);
            }
        if(nonZeroRank[2] != 1000){
            ans += 9 * (nonZeroRank[2] - 1);
            ans += (int)N[nonZeroN[2]] - 48;
        }
    }

    cout << ans << endl;

    return 0;

}
