#include <bits/stdc++.h>
using namespace std;
double a[200005];
int main() {
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long n = s.length();
  if (k == 1) {
    cout << (s[0] - '0') + (n - 1) * 9 << endl;
  }
  if (k == 2) {
    long long num = n - k;
    num = (num * (num + 1)) / 2;
    num *= (long long)81;
    long long pos = 1;
    while (pos < n && s[pos] == '0') pos++;
    if (pos != n) {
      num += (long long)(s[pos] - '0');
      num += (n - pos - 1) * (long long)9;
    }
    for (long long i = 1; i < (long long)(s[0] - '0'); i++) {
      num += (n - 1) * (long long)9;
    }
    cout << num << endl;
  }
  if (k == 3) {
    long long num = 0;
    for (long long i = 2; i < n - 1; i++) {
      num += (i * (i - 1)) / 2;
    }
    num *= (long long)729;
    long long cnt = 0, x, y;
    for (long long i = 1; i < n; i++) {
      if (cnt == 2) break;
      if (s[i] != '0') {
        cnt++;
        if (cnt == 1) {
          num += ((n - i - 1) * (n - i - 2)) / 2 * 81;
          x = i;
          y = s[i] - '0';
        }
        if (cnt == 2) {
          num += y * ((s[i] - '0') + (n - i - 1) * 9);
        }
      }
    }
    for (long long i = 1; i < (long long)(s[0] - '0'); i++) {
      num += ((n - 1) * (n - 2)) / 2 * (long long)81;
    }
    cout << num << endl;
  }
}
