#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout<< name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define end_time()
#endif


#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

lli triangle[105][105];
void go(){
    triangle[0][0] = 1;
    for(int i = 0; i<105; i++){
        triangle[i][0] = 1;
        for(int j = 0; j<105; j++){
            triangle[i][j] = triangle[i-1][j] + triangle[i-1][j-1];
        }
    }
    return;
}
void solve(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    int f1 = (int)s[0] - (int)'0';
    int l = s.length();
    int ans = 0;
    if(k==1){
        ans = (9*(l-1)) + f1;
    }
    if(k==2){
        if(l>=2){
            int f2 = (int)s[1] - (int)'0';
            ans=(triangle[l-1][2]*81) +((f1-1)*(l-1)*9) +f2 + ((l-2)*9);
        }
    }
    if(k==3){
        if(l>=3){
            int f2 = (int)s[1] - (int)'0';
            int f3 = (int)s[2] - (int)'0';
            ans = (729*triangle[l-1][3]) + (81*(f1-1)*triangle[l-1][2]) + (81*triangle[l-2][2]) + (9*(f2-1)*(l-2)) + (9*(l-3)) + f3;
        }
    }
}
signed main(){
    speedX;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    //cin>>t;
    go();
    while(t--){
        solve();
    }
    end_time();
    return 0;
}