#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)1e9 + 7;
const double EPS = 1e-9;
string N;
long long K;
long long DP[110][2][5];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  DP[0][0][0] = 1;
  for (long long i = (0), i_len = (((long long)(N).size())); i < i_len; i++) {
    for (long long j = (0), j_len = (10); j < j_len; j++) {
      if (j > N[i] - '0') {
        DP[i + 1][1][1] += DP[i][1][0];
        DP[i + 1][1][2] += DP[i][1][1];
        DP[i + 1][1][3] += DP[i][1][2];
      } else if (j == N[i] - '0') {
        if (j == 0) {
          DP[i + 1][1][0] += DP[i][1][0];
          DP[i + 1][1][1] += DP[i][1][1];
          DP[i + 1][1][2] += DP[i][1][2];
          DP[i + 1][1][3] += DP[i][1][3];
          DP[i + 1][0][0] += DP[i][0][0];
          DP[i + 1][0][1] += DP[i][0][1];
          DP[i + 1][0][2] += DP[i][0][2];
          DP[i + 1][0][3] += DP[i][0][3];
        } else {
          DP[i + 1][1][1] += DP[i][1][0];
          DP[i + 1][1][2] += DP[i][1][1];
          DP[i + 1][1][3] += DP[i][1][2];
          DP[i + 1][0][1] += DP[i][0][0];
          DP[i + 1][0][2] += DP[i][0][1];
          DP[i + 1][0][3] += DP[i][0][2];
        }
      } else {
        if (j == 0) {
          DP[i + 1][1][0] += DP[i][1][0];
          DP[i + 1][1][1] += DP[i][1][1];
          DP[i + 1][1][2] += DP[i][1][2];
          DP[i + 1][1][3] += DP[i][1][3];
          DP[i + 1][1][0] += DP[i][0][0];
          DP[i + 1][1][1] += DP[i][0][1];
          DP[i + 1][1][2] += DP[i][0][2];
        } else {
          DP[i + 1][1][1] += DP[i][1][0];
          DP[i + 1][1][2] += DP[i][1][1];
          DP[i + 1][1][3] += DP[i][1][2];
          DP[i + 1][1][1] += DP[i][0][0];
          DP[i + 1][1][2] += DP[i][0][1];
          DP[i + 1][1][3] += DP[i][0][2];
        }
      }
    }
  }
  cout << DP[((long long)(N).size())][0][K] + DP[((long long)(N).size())][1][K]
       << endl;
  return 0;
}
