#include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
const int N = 100000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int mod = (int)1e9 + 7;
const int mod1 = (int)1e9 + 9;
const int mod2 = 998244353;
const int mod3 = (int)1e6 + 3;
const long double eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
void lineFromPoints(pair<double, double> P, pair<double, double> Q, double &a,
                    double &b, double &c) {
  a = Q.second - P.second;
  b = P.first - Q.first;
  c = a * (P.first) + b * (P.second);
}
void perpendicularBisectorFromLine(pair<double, double> P,
                                   pair<double, double> Q, double &a, double &b,
                                   double &c) {
  pair<double, double> mid_point =
      make_pair((P.first + Q.first) / 2, (P.second + Q.second) / 2);
  c = -b * (mid_point.first) + a * (mid_point.second);
  double temp = a;
  a = -b;
  b = temp;
}
pair<double, double> lineLineIntersection(double a1, double b1, double c1,
                                          double a2, double b2, double c2) {
  double determinant = a1 * b2 - a2 * b1;
  if (determinant == 0) {
    return make_pair(FLT_MAX, FLT_MAX);
  } else {
    double x = (b2 * c1 - b1 * c2) / determinant;
    double y = (a1 * c2 - a2 * c1) / determinant;
    return make_pair(x, y);
  }
}
pair<double, double> findCircumCenter(pair<double, double> P,
                                      pair<double, double> Q,
                                      pair<double, double> R,
                                      pair<double, double> S) {
  double a, b, c;
  lineFromPoints(P, Q, a, b, c);
  double e, f, g;
  lineFromPoints(R, S, e, f, g);
  perpendicularBisectorFromLine(P, Q, a, b, c);
  perpendicularBisectorFromLine(R, S, e, f, g);
  pair<double, double> circumcenter = lineLineIntersection(a, b, c, e, f, g);
  return circumcenter;
}
double dis(double x1, double x2, double y1, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string n;
  cin >> n;
  int k;
  cin >> k;
  int i, j;
  int len = n.length();
  int ans[len][3];
  int isallzero[len];
  isallzero[0] = 0;
  for (int i = (0); i < (len); i++) {
    ans[i][0] = n[0] - '0' + 9 * i;
  }
  for (int i = (1); i < (len); i++) {
    if (n[i] == 0 && isallzero[i - 1] == 0) {
      isallzero[i] = 0;
    } else {
      isallzero[i] = 1;
    }
  }
  for (int i = (0); i < (3); i++) {
    ans[0][1] = 0;
    ans[0][2] = 0;
  }
  for (int i = (1); i < (len); i++) {
    for (int j = (1); j < (3); j++) {
      if (n[i] != 0 && isallzero[i - 1] == 1) {
        ans[i][j] = ans[i - 1][j - 1] * 9 + ans[i - 1][j];
      } else if (n[i] != 0 && isallzero[i - 1] == 0) {
        ans[i][j] = ans[i - 1][j - 1] * 9 - (9 - n[i] + '0') + ans[i - 1][j];
      } else {
        ans[i][j] = ans[i - 1][j];
      }
    }
  }
  cout << ans[len - 1][k - 1];
}
