#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
string s;
long long k;
signed main() {
  ios::sync_with_stdio(false);
  cin >> s >> k;
  long long len = s.length();
  s = '*' + s;
  if (k == 3) {
    while (1)
      ;
    long long res = 0;
    for (long long i = 1; i <= s.length(); ++i) {
      for (long long j = i + 1; j <= len; ++j)
        for (long long k = j + 1; k <= len; ++k) {
          res++;
        }
    }
    res *= 9 * 9 * 9;
    long long ALL = 0;
    for (long long i = 2; i <= len; ++i) {
      if (s[i] == '0') {
        ALL += len - i;
      } else {
        break;
      }
    }
    ALL *= 9 * 9;
    for (long long i = 2; i <= len; ++i) {
      if (s[i] == '0') {
      } else {
        ALL += (len - i) * 9 * ('9' - s[i]);
        for (long long j = i + 1; j <= len; ++j) {
          if (s[j] == '0')
            ALL += 9;
          else {
            ALL += '9' - s[i];
            break;
          }
        }
        break;
      }
    }
    long long tt = 0;
    for (long long i = 1; i <= len - 1; ++i) {
      for (long long j = i + 1; j <= len - 1; ++j) {
        tt++;
      }
    }
    tt *= 9 * 9;
    tt *= '9' - s[1];
    ALL += tt;
    res -= ALL;
    cout << res << endl;
    return 0;
  }
  if (k == 2) {
    long long res = 0;
    for (long long i = 1; i <= len; ++i) {
      for (long long j = i + 1; j <= len; ++j) {
        for (long long k = 1; k <= 9; ++k)
          for (long long l = 1; l <= 9; ++l) {
            long long ok = 1;
            for (long long m = 1; m <= len; ++m) {
              char this_;
              if (m == i) {
                this_ = char('0' + k);
              } else if (m == j) {
                this_ = char('0' + l);
              } else {
                this_ = '0';
              }
              if (s[m] < this_) {
                ok = 0;
                break;
              }
              if (s[m] == this_) continue;
              break;
            }
            res += ok;
          }
      }
    }
    cout << res;
  } else {
    long long res = 0;
    for (long long i = 1; i <= len; ++i) {
      for (long long j = 1; j <= 9; ++j) {
        long long ok = 1;
        for (long long m = 1; m <= len; ++m) {
          char this_;
          if (m == i) {
            this_ = char('0' + j);
          } else
            this_ = '0';
          if (s[m] < this_) {
            ok = 0;
            break;
          }
          if (s[m] == this_) continue;
          break;
        }
        res += ok;
      }
    }
    cout << res;
  }
  return 0;
}
