#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long get_digits(long long N) {
  long long counter = 0;
  while (N > 0) {
    N = N / 10;
    counter++;
  }
  return counter;
}
int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long N, K;
  cin >> N >> K;
  long long order = get_digits(N);
  int k = K;
  ;
  long long counter = 0;
  int bit = (1 << k) - 1;
  for (; bit < (1 << order); bit = next_combination(bit)) {
    vector<int> S;
    for (int i = 0; i < order; ++i) {
      if (bit & (1 << i)) {
        S.push_back(i);
      }
    };
    if (K == 3) {
      for (int l = (1); l < (10); l++) {
        for (int k = (1); k < (10); k++) {
          for (int j = (1); j < (10); j++) {
            long long res = 0;
            long long pos = 0;
            for (int i = 0; i < (int)(K); i++) {
              long long n;
              if (pos == 0) {
                n = j;
              } else if (pos == 1) {
                n = k;
              } else {
                n = l;
              }
              res += n * pow(10, S[pos]);
              pos++;
            }
            if (res <= N) counter++;
            ;
          }
        }
      }
    } else if (K == 2) {
      for (int k = (1); k < (10); k++) {
        for (int j = (1); j < (10); j++) {
          long long res = 0;
          long long pos = 0;
          for (int i = 0; i < (int)(K); i++) {
            long long n;
            if (pos == 0) {
              n = j;
            } else {
              n = k;
            }
            res += n * pow(10, S[pos]);
            pos++;
          }
          if (res <= N) counter++;
          ;
        }
      }
    } else {
      for (int j = (1); j < (10); j++) {
        long long res = 0;
        long long n = j;
        res += n * pow(10, S[0]);
        if (res <= N) counter++;
        ;
      }
    }
  };
  cout << counter << endl;
  return 0;
}
