#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long INF = 1LL << 60;
using vll = vector<long long>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pair<long long, long long> = pair<long long, long long>;
using vc = vector<char>;
using vvc = vector<vc>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
long long dp[105][2][4];
int main() {
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long n = (long long)(s).size();
  memset(dp, 0, sizeof(dp));
  for (long long i = 0; i < (n); i++) {
    long long nd = s[i] - '0';
    for (long long j = 0; j < (2); j++) {
      for (long long z = 0; z < (4); z++) {
        for (long long u = 0; u < (10); u++) {
          long long ni = i + 1, nj = j, nz = z;
          if (nj == 0 && nd < u) continue;
          if (nj == 0 && nd > u) nj = 1;
          if (u != 0) nz++;
          if (nz > 3) continue;
          dp[ni][nj][nz] += dp[i][j][z];
        }
      }
    }
  }
  cout << (dp[n][0][k] + dp[n][1][k]) << endl;
}
