#include <bits/stdc++.h>
using namespace std;
long long low(vector<long long> a, long long b) {
  decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b);
  long long d = c - a.begin();
  return d;
}
long long upp(vector<long long> a, long long b) {
  decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b);
  long long d = c - a.begin();
  return d;
}
template <class T>
void cou(vector<vector<T>> a) {
  long long b = a.size();
  long long c = a[0].size();
  for (long long i = 0; i < b; i++) {
    for (long long j = 0; j < c; j++) {
      cout << a[i][j];
      if (j == c - 1)
        cout << endl;
      else
        cout << ' ';
    }
  }
}
long long wari(long long a, long long b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
long long keta(long long a) {
  long double b = a;
  b = log10(b);
  long long c = b;
  return c + 1;
}
long long souwa(long long a) { return a * (a + 1) / 2; }
long long gcm(long long a, long long b) {
  if (a % b == 0) return b;
  return gcm(b, a % b);
}
bool prime(long long a) {
  if (a < 2)
    return false;
  else if (a == 2)
    return true;
  else if (a % 2 == 0)
    return false;
  for (long long i = 3; i <= sqrt(a) + 1; i += 2) {
    if (a % i == 0) return false;
  }
  return true;
}
struct Union {
  vector<long long> par;
  Union(long long a) { par = vector<long long>(a, -1); }
  long long find(long long a) {
    if (par[a] < 0)
      return a;
    else
      return par[a] = find(par[a]);
  }
  bool same(long long a, long long b) { return find(a) == find(b); }
  long long Size(long long a) { return -par[find(a)]; }
  void unite(long long a, long long b) {
    a = find(a);
    b = find(b);
    if (a == b) return;
    if (Size(b) > Size(a)) swap<long long>(a, b);
    par[a] += par[b];
    par[b] = a;
  }
};
long long ketas(long long a) {
  string b = to_string(a);
  long long c = 0;
  for (long long i = 0; i < keta(a); i++) {
    c += b[i] - '0';
  }
  return c;
}
bool fe(long long a, long long b) {
  a %= 10;
  b %= 10;
  if (a == 0) a = 10;
  if (b == 0) b = 10;
  if (a > b)
    return true;
  else
    return false;
}
long long INF = 1000000007;
struct edge {
  long long s, t, d;
};
vector<long long> mojisyu(string a) {
  vector<long long> b(26, 0);
  for (long long i = 0; i < a.size(); i++) {
    b[a[i] - 'a']++;
  }
  return b;
}
long long wa2(long long a) {
  if (a % 2 == 1) return a / 2;
  return a / 2 - 1;
}
long long nCr(long long n, long long r) {
  if (n < r) return 0;
  long long a = 1;
  r = min(r, n - r);
  for (long long i = n; i > n - r; i--) {
    a *= i;
    a /= n - i + 1;
  }
  return a;
}
long long kaijou(long long a) {
  long long b = 1;
  for (long long i = 0; i < a; i++) b *= i + 1;
  return b;
}
long long nPr(long long a, long long b) {
  if (a < b) return 0;
  if (b == 0) return 1;
  long long c = 1;
  for (long long i = a; i > a - b; i--) {
    c *= i;
    c %= INF;
  }
  return c;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long lcm(long long a, long long b) {
  long long c = modinv(gcm(a, b), INF);
  return ((a * c) % INF) * (b % INF) % INF;
}
long long MOD = INF;
long long fac[1000010], finv[1000010], inv[1000010];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < 1000010; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool naka(long long a, long long b, vector<vector<char>> c) {
  return (a >= 0 && b >= 0 && a < c.size() && b < c[0].size());
}
vector<pair<long long, long long>> mawari8 = {
    {0, -1}, {0, 1}, {1, 0}, {-1, 0}, {-1, -1}, {1, 1}, {1, -1}, {-1, -1}};
long long inf = 1000000000000000007;
vector<pair<long long, long long>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
vector<long long> onajibubun(string a) {
  vector<long long> b(a.size());
  for (long long i = 1, j = 0; i < a.size(); i++) {
    if (i + b[i - j] < j + b[j])
      b[i] = b[i - j];
    else {
      long long c = max<long long>(0, j + b[j] - i);
      while (i + c < a.size() && a[c] == a[i + c]) c++;
      b[i] = c;
      j = i;
    }
  }
  b[0] = a.size();
  return b;
}
vector<long long> color(205);
bool nibu_hantei(long long a, long long b, vector<vector<long long>> c) {
  color[a] = b;
  for (long long i = 0; i < c[a].size(); i++) {
    if (b == color[c[a][i]]) return false;
    if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c)) return false;
  }
  return true;
}
bool renketujanai_nibu_hantei(long long a, vector<vector<long long>> c) {
  for (long long i = 0; i < a; i++) {
    if (color[i] == 0) {
      if (!nibu_hantei(i, 1, c)) return false;
    }
  }
  return true;
}
long long uk1(string a, long long b) {
  long long c = 0;
  long long d = pow(9, b);
  for (long long i = b; i < a.size(); i++) {
    c += d * nCr(i - 1, b - 1);
  }
  if (a.size() >= b) {
    if (b == 1) {
      c += a[0] - '0';
    }
  }
  return c;
}
long long uk2(string a, long long b) {
  long long c = 0;
  long long d = pow(9, b);
  for (long long i = b; i < a.size(); i++) {
    c += d * nCr(i - 1, b - 1);
  }
  if (a.size() >= b) {
    if (b == 2) {
      c += ((a[0] - '0') - 1) * 9 * nCr(a.size() - 1, 1);
      c += 1 * (a[1] - '0');
      if (a.size() > 2) c += uk1(a.substr(2), 1);
    }
  }
  return c;
}
signed main() {
  string a;
  cin >> a;
  long long b;
  cin >> b;
  long long c = 0;
  long long d = pow(9, b);
  for (long long i = b; i < a.size(); i++) {
    c += d * nCr(i - 1, b - 1);
  }
  if (a.size() >= b) {
    if (b == 1) {
      c += a[0] - '0';
    }
    if (b == 2) {
      c += ((a[0] - '0') - 1) * 9 * nCr(a.size() - 1, 1);
      c += 1 * (a[1] - '0');
      if (a.size() > 2) c += uk1(a.substr(2), 1);
    }
    if (b == 3) {
      c += ((a[0] - '0') - 1) * 81 * nCr(a.size() - 1, 2);
      if (a.size() > 1) c += 1 * ((a[1] - '0') - 1) * 9 * nCr(a.size() - 2, 1);
      c += uk2(a.substr(2), 2);
      if (a.size() > 2) c += 1 * 1 * (a[2] - '0');
      if (a.size() > 3) c += uk1(a.substr(3), 1);
    }
  }
  cout << c << endl;
}
