#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;

ll C(int n, int r) {
    if(r > n - r) r = n - r; 
    ll ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n;
    int k;
    cin >> n >> k;
    int d =  n.size();
    if (d < k) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    ans += (ll)pow(9, k)*C(d-1, k);
    int m = stoi(string(1,n[0]));

    if(d >= 3){
        ans += (ll) m * pow(9, k-1) * C(d-2, k-1);
    }

    if(k>=2){
        if(d>=1){
            int mm = stoi(string(1,n[1]));
            ll s = (ll) 9*(m-1) + mm;
            if (k==2) ans += s;
        else if (k>=3){
            int mmm = stoi(string(1,n[2]))
            ans += (ll) s*(9*(d-3) + mmm);
            }        
        }
    }
    cout << ans << endl;


}