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

//     d     4
int dp[101][2][4];
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N, K;
    cin >> N >> K;
    // 桁数１−１０0 => d 
    // dC_K の和?
    string s = to_string(N);
    int len = s.length();
    dp[0][0][0] = 1;
    for (int d = 0; d < len; d++) {
        for (int smaller = 0; smaller < 2; smaller++) {
            for (int k = 0; k <= K; k++) {
                for (int x = 0; x <= (smaller ? 9 : (s[d] - '0')); x++) {
                    dp[d + 1][smaller || x < (s[d] - '0')][(x != 0 ? k + 1 : k)] += dp[i][smaller][k];
                }
            }
        }
    }
    cout << dp[len][0][3] + dp[len][1][3] << endl;


    return 0;
}