#include <bits/stdc++.h>
#pragma target("avx")
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const long long LINF = 1e18;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), n, s;
long long cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
long long dp[1000][1000];
map<string, long long> mp;
long long comb(long long nn, long long k) {
  if (nn < k) return 0;
  if (dp[nn][k] != 0) return dp[nn][k];
  if (k == 0) return dp[nn][k] = 1;
  if (nn == k) return dp[nn][k] = 1;
  return dp[nn][k] = comb(nn - 1, k - 1) + comb(nn - 1, k);
}
void dfs(long long i, long long j, int fl) {
  if (i > (n).size() || j > k) return;
  if (i != 0) {
    if ((n[i] - '0') == 0)
      dfs(i + 1, j, 0);
    else
      dfs(i + 1, j, 1);
  }
  long long now;
  for (long long z = (1); z < (10); z++) {
    if (fl == 1) {
      dfs(i + 1, j + 1, 1);
    } else {
      if ((n[i] - '0') < z) continue;
      if ((n[i] - '0') == z)
        now = 0;
      else
        now = 1;
      dfs(i + 1, j + 1, now);
    }
  }
  if (j == k && i == (n).size()) {
    ans++;
  }
}
int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  if ((n).size() < k) {
    cout << (0) << endl;
    return 0;
  }
  long long kakeru = 1;
  for (long long(i) = 0; (i) < (int)(k); (i)++) kakeru *= 9;
  for (long long i = (k); i < ((n).size()); i++) {
    if (i < k) continue;
    ans += max(comb(i - 1, k - 1), 1LL) * kakeru;
  }
  vector<long long> p(9);
  for (long long zz = (1); zz < (10); zz++) {
    for (long long zzz = (1); zzz < (10); zzz++) {
      for (long long zzzz = (1); zzzz < (10); zzzz++) {
        p[0] = zz;
        p[1] = zzz;
        p[2] = zzzz;
        s = to_string(p[0]);
        if (k >= 2) s += to_string(p[1]);
        if (k >= 3) s += to_string(p[2]);
        if (mp[s]) continue;
        mp[s] = 1;
        if (p[0] > (n[0] - '0')) continue;
        if (k == 1)
          ans++;
        else {
          for (long long i = (1); i < ((n).size()); i++) {
            if (k == 3) {
              for (long long j = (i + 1); j < ((n).size()); j++) {
                int ok = 0;
                for (long long z = (0); z < ((n).size()); z++) {
                  if (z == 0) {
                    if ((s[0] - '0') == (n[z] - '0')) continue;
                    if ((s[0] - '0') < (n[z] - '0')) {
                      break;
                    } else {
                      ok = 1;
                      break;
                    }
                  } else if (z == i) {
                    if ((s[1] - '0') == (n[z] - '0')) continue;
                    if ((s[1] - '0') < (n[z] - '0')) {
                      break;
                    } else {
                      ok = 1;
                      break;
                    }
                  } else if (z == j) {
                    if ((s[2] - '0') == (n[z] - '0')) continue;
                    if ((s[2] - '0') < (n[z] - '0')) {
                      break;
                    } else {
                      ok = 1;
                      break;
                    }
                  } else {
                    if (0 < (n[z] - '0')) {
                      break;
                    } else {
                      ok = 1;
                      break;
                    }
                  }
                }
                if (!ok) ans++;
              }
            } else if (k == 2) {
              int ok = 0;
              for (long long z = (0); z < ((n).size()); z++) {
                if (z == 0) {
                  if ((s[0] - '0') == (n[z] - '0')) continue;
                  if ((s[0] - '0') < (n[z] - '0')) {
                    break;
                  } else {
                    ok = 1;
                    break;
                  }
                } else if (z == i) {
                  if ((s[1] - '0') == (n[z] - '0')) continue;
                  if ((s[1] - '0') < (n[z] - '0')) {
                    break;
                  } else {
                    ok = 1;
                    break;
                  }
                } else {
                  if (0 < (n[z] - '0')) {
                    break;
                  } else {
                    ok = 1;
                    break;
                  }
                }
              }
              if (!ok) ans++;
            }
          }
        }
      }
    }
  }
  cout << (ans) << endl;
  return 0;
}
