#include <iostream>
#include <algorithm>
#include <string>

using namespace std;


long long combi(int n, int k) {
    
    long long answer = 1;

    for (long long i = n; i > n - k; i--) {
        answer *= i;
    }

    for (long long i = 2; i <= k; i++) {
        answer /= i;
    }

    return answer;
}




int main()
{
    string n;
    int k;

    long long answer = 0;

    cin >> n >> k;

    int keta = n.length() - 1;


    if(keta + 1 < k){
        cout << 0 << endl;
        return 0;
    }
    else if (k < keta + 1) {
        answer += combi(keta, k) * pow(9, k);
    }




    k--;
    if (k <= 0) {
        cout << answer + atoi(n.substr(0, 1).c_str()) << endl;
        return 0;
    }
    
    for (int i = 1; i < atoi(n.substr(0,1).c_str()); i++) {
        answer += combi(keta, k) * pow(9, k);
    }

    n = n.substr(1, n.length() - 1);

    k--; keta--;
    if (k <= 0) {
        if (keta >= 2) { answer += combi(keta - 2, 1) * pow(9, k); }
        cout << answer + atoi(n.substr(0, 1).c_str()) << endl;
        return 0;
    }




    for (int i = 1; i < atoi(n.substr(0, 1).c_str()); i++) {
        answer += combi(keta, k) * pow(9, k);
    }

    n = n.substr(1, n.length() - 1);



    if(keta >= 2) { answer += combi(keta - 2, 1) * pow(9, k); }
 
    cout << answer + atoi(n.substr(0, 1).c_str()) << endl;

    return 0;
    
}