#include <bits/stdc++.h>
using namespace std;
inline long long toLong(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-5;
const double PI = acos(-1.0);
long long dp[105][5] = {{0}};
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  long long k;
  cin >> s >> k;
  long long sz = long long((s).size());
  for (long long i = (0); i < (sz); ++i) {
    long long keta = sz - i;
    long long x = s[i] - '0';
    dp[i][0] = 0;
    if (x == 0) {
      dp[i][1] = 0;
      dp[i][2] = 0;
      dp[i][3] = 0;
      if (i != 0) {
        dp[i][1] += dp[i - 1][1];
        dp[i][2] += dp[i - 1][2];
        dp[i][3] += dp[i - 1][3];
      }
      continue;
    }
    if (i == 0) {
      dp[i][1] = 9 * (keta - 1) + x;
      if (keta >= 2) {
        dp[i][2] = 81 * (keta - 1) * (keta - 2) / 2 + (x - 1) * 9 * (keta - 1);
      } else {
        dp[i][2] = 0;
      }
      if (keta >= 3) {
        dp[i][3] = 9 * 9 * 9 * (keta - 1) * (keta - 2) * (keta - 3) / 6 +
                   (x - 1) * 81 * (keta - 1) * (keta - 2) / 2;
      } else {
        dp[i][3] = 0;
      }
    }
    if (i == 1) {
      dp[i][1] = 0;
      dp[i][2] = 9 * (keta - 1) + x;
      if (keta >= 2) {
        dp[i][3] = 81 * (keta - 1) * (keta - 2) / 2 + (x - 1) * 9 * (keta - 1);
      } else {
        dp[i][3] = 0;
      }
    }
    if (i == 2) {
      dp[i][1] = 0;
      dp[i][2] = 0;
      dp[i][3] = 9 * (keta - 1) + x;
    }
    if (i != 0) {
      dp[i][1] += dp[i - 1][1];
      dp[i][2] += dp[i - 1][2];
      dp[i][3] += dp[i - 1][3];
    }
  }
  cout << (dp[sz - 1][k]) << endl;
  ;
}
