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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    string N;
    int K;
    cin >> N >> K;
    const auto calc = [](int x) {
        int cnt = 0;
        while (x) {
            cnt += x%10 != 0;
            x /= 10;
        }
        return cnt;
    };
    int sz = N.size();
    ll *dp2 = new ll[sz+1]();
    ll *dp3 = new ll[sz+1]();
    Fr(i, 0, sz) dp2[i+1] = dp2[i] + 81*i;
    Fr(i, 0, sz) dp3[i+1] = dp3[i] + 9*dp2[i];
    //Fr(i, 0, sz) cerr << dp2[i+1] << " \n"[i+1==sz];
    //Fr(i, 0, sz) cerr << dp3[i+1] << " \n"[i+1==sz];
    const auto get = [&](int k, int l) {
        switch (k) {
        case 0:
            return 1LL;
            break;
        case 1:
            return l*9LL;
            break;
        case 2:
            return dp2[l];
            break;
        case 3:
            return dp3[l];
            break;
        default:
            assert(false);
            break;
        }
    };
    ll ans = 0;
    int no = 0, ed = min(sz, K);
    Fr(i, 0, ed) {
        ans += (N[i]-'0'-1)*get(K-1-no, sz-1-no) + get(K-no, sz-1-no);
        no += N[i]!='0';
    }
    ans += sz >= K;
    cout << ans << endl;

}
