#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
template <typename T>
bool chmax(T &a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
ll pow2(const T n) {
  return (1LL << n);
}
template <typename T>
void cosp(const T n) {
  cout << n << ' ';
}
template <typename T>
void co(const T n) {
  cout << n << endl;
}
template <typename T1, typename T2>
void co(pair<T1, T2> p) {
  cout << p.first << ' ' << p.second << endl;
}
template <typename T>
void co(const Vec1<T> &v) {
  for (T i : v) cosp(i);
  cout << endl;
}
template <typename T>
void co(initializer_list<T> v) {
  for (T i : v) cosp(i);
  cout << endl;
}
template <typename T>
void ce(const T n) {
  cerr << n << endl;
}
void sonic() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void setp(const ll n) { cout << fixed << setprecision(n); }
const ll INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ld EPS = 1e-11;
ll count() {
  ll res = 0;
  for (ll(i) = (0); (i) < (1000); ++(i)) {
    ll a, b, c, n = i;
    a = n % 10;
    n /= 10;
    b = n % 10;
    c = n / 10;
    if (!a || !b || !c) continue;
    res++;
  }
  return res;
}
bool f(ll n, ll i, ll j, ll k, string s) {
  ll a, b, c;
  a = n % 10;
  n /= 10;
  b = n % 10;
  c = n / 10;
  if (!a || !b || !c) return false;
  string t;
  for (ll(i) = (0); (i) < (s.size()); ++(i)) t += '0';
  t[i] = a + '0';
  t[j] = b + '0';
  t[k] = c + '0';
  return t < s;
}
int main(void) {
  string s;
  cin >> s;
  ll n;
  cin >> n;
  ll l = s.size(), p = count();
  ll ans = 0;
  if (n == 3)
    for (ll(i) = (0); (i) < (l - 2); ++(i)) {
      for (ll(j) = (i + 1); (j) < (l - 1); ++(j)) {
        for (ll(k) = (j + 1); (k) < (l); ++(k)) {
          if (f(111, i, j, k, s)) {
            ans += p;
            continue;
          } else if (!f(999, i, j, k, s)) {
            continue;
          }
          for (ll(m) = (0); (m) < (1000); ++(m)) {
            ll a, b, c, z = m;
            a = z % 10;
            z /= 10;
            b = z % 10;
            c = z / 10;
            if (!a || !b || !c) continue;
            string t;
            for (ll(i) = (0); (i) < (s.size()); ++(i)) t += '0';
            t[i] = a + '0';
            t[j] = b + '0';
            t[k] = c + '0';
            if (s >= t) ans++;
          }
        }
      }
    }
  else if (n == 2)
    for (ll(i) = (0); (i) < (l - 1); ++(i)) {
      for (ll(j) = (i + 1); (j) < (l); ++(j)) {
        for (ll(m) = (0); (m) < (100); ++(m)) {
          ll a, b, z = m;
          a = z % 10;
          b = z / 10;
          if (!a || !b) continue;
          string t;
          for (ll(i) = (0); (i) < (s.size()); ++(i)) t += '0';
          t[i] = a + '0';
          t[j] = b + '0';
          if (s >= t) {
            ans++;
          }
        }
      }
    }
  else
    for (ll(i) = (0); (i) < (l); ++(i)) {
      for (ll(m) = (0); (m) < (10); ++(m)) {
        ll a, z = m;
        a = z % 10;
        if (!a) continue;
        string t;
        for (ll(i) = (0); (i) < (s.size()); ++(i)) t += '0';
        t[i] = a + '0';
        if (s >= t) {
          ans++;
        }
      }
    }
  co(ans);
  return 0;
}
