#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e8;
const ll N = 2e5 + 1;

int ncr (int x, int y)
{
    if (x < y) return 0;
    if (y == 0) return 1;
    if (y == 1) return x;
    if (y == 2) return x*(x-1)/2;
    if (y == 3) return x*(x-1)*(x-2)/6;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string str;
    int k, ans = 0;
    cin >> str >> k;
    
    int po[4] = {1, 9, 27, 729}, z = k;
    FOR (i, 0, sz(str) - 1)
    {
        int d = str[i] - 48, l = sz(str) - 1 - i;
        if (!d) continue;
        
        ans += ncr(l, z) * po[z];
       // cout << ncr(l, z) << " " << po[z] << endl;
        z--;
        if (z < 0) {cout << ans; return 0;}
        ans += (d - 1) * ncr(l, z) * po[z];
    }
    
    cout << ans + 1;
}




























