#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;
string a;
int K;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> a >> K;
  int n = int((a).size());
  int res = 0;
  for (int len = (K); len <= (n); len++) {
    if (len < n) {
      if (K == 1) {
        res += 9;
      } else if (K == 2) {
        for (int j = (2); j <= (len); j++) res += 9 * 9;
      } else {
        for (int j = (2); j <= (len); j++)
          for (int k = (j + 1); k <= (len); k++) res += 9 * 9 * 9;
      }
    } else {
      if (K == 1) {
        res += a[0] - '0' - 1;
      } else if (K == 2) {
        for (int j = (2); j <= (len); j++) res += (a[0] - '0' - 1) * 9;
      } else {
        for (int j = (2); j <= (len); j++)
          for (int k = (j + 1); k <= (len); k++)
            res += (a[0] - '0' - 1) * 9 * 9;
      }
      if (K == 1) res++;
      if (K == 2) {
        bool hasBigger = false;
        for (int j = (2); j <= (len); j++) {
          if (hasBigger)
            res += 9;
          else {
            if (a[j - 1] > '0') {
              res += a[j - 1] - '0';
              hasBigger = true;
            }
          }
        }
      }
      if (K == 3) {
        bool hasBigger = false;
        for (int j = (2); j <= (len); j++) {
          if (hasBigger) {
            for (int k = (j + 1); k <= (len); k++) res += 9 * 9;
          } else {
            if (a[j - 1] > '0') {
              bool hasBigger2 = false;
              for (int k = (j + 1); k <= (len); k++) {
                if (hasBigger2)
                  res += (a[j - 1] - '0') * 9;
                else {
                  if (a[k - 1] > '0') {
                    res += (a[j - 1] - '0') * (a[k - 1] - '0');
                    hasBigger2 = true;
                  }
                }
              }
              hasBigger = true;
            }
          }
        }
      }
    }
  }
  cout << res;
  return 0;
}
