#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  UnionFind(int n = 1) { init(n); }
  void init(int n = 1) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    return true;
  }
};
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
int main() {
  string N;
  int k;
  cin >> N;
  cin >> k;
  long long z = N.at(0) - '0';
  long long size = N.size();
  long long ans = 0;
  if (size < k) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    if (size - 1 >= 1) {
      ans += (size - 1) * 9;
    }
    ans += z - 1;
    ans += 1;
  }
  if (k == 2) {
    if (size - 1 >= 2) {
      ans += (size - 1) * (size - 2) / 2 * 81;
    }
    if (size - 1 >= 1) {
      long long z2 = N.at(1) - '0';
      ans += (z - 1) * (size - 1) * 9;
      ans += (size - 2) * 9 + z2;
    }
  }
  if (k == 3) {
    if (size - 1 >= 3) {
      ans += (size - 1) * (size - 2) * (size - 3) / 6 * 9 * 9 * 9;
    }
    if (size - 1 >= 2) {
      ans += (z - 1) * (size - 1) * (size - 2) / 2 * 9 * 9;
    }
    if (size - 2 >= 2) {
      ans += (size - 2) * (size - 3) / 2 * 9 * 9;
    }
    if (size - 2 >= 0) {
      long long z2 = N.at(1) - '0';
      ans += (z2 - 1) * (size - 2) * 9;
    }
    if (size - 3 >= 1) {
      ans += (size - 3) * 9;
    }
    if (size >= 3) {
      long long z3 = N.at(2) - '0';
      ans += z3;
    }
  }
  cout << ans << endl;
}
