#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  cin >> N;
  int K;
  cin >> K;
  if (K == 1) {
    if (N.size() == 1) cout << N[0] << endl;
    if (N.size() > 1) {
      int n = N[0] - '0';
      int64_t ans;
      ans += (int64_t)pow(9, N.size() - 1);
      ans += n;
      cout << ans << endl;
    }
  } else if (K == 2) {
    if (N.size() == 1)
      cout << 0 << endl;
    else if (N.size() >= 2) {
      int n = N.size();
      int64_t sum = 0;
      vector<int> a(n, 0);
      for (int i = 0; i < N.size(); ++i) {
        a[i] = N[i] - '0';
      }
      for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
          for (int k = 0; k < n; ++k) {
            for (int l = k + 1; l < n; ++l) {
              vector<int> b(n, 0);
              b[k] = i;
              b[l] = j;
              if (a >= b) {
                ++sum;
              }
            }
          }
        }
      }
      cout << sum << endl;
    }
  } else if (K == 3) {
    if (N.size() <= 2)
      cout << 0 << endl;
    else {
      int n = N.size();
      int64_t sum = 0;
      vector<int> v(n, 0);
      for (int i = 0; i < N.size(); ++i) {
        v[i] = N[i] - '0';
      }
      for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
          for (int k = 1; k <= 9; ++k) {
            for (int a = 0; a < n; ++a) {
              for (int b = a + 1; b < n; ++b) {
                for (int c = b + 1; c < n; ++c) {
                  vector<int> w(n, 0);
                  w[a] = i;
                  w[b] = j;
                  w[c] = k;
                  if (v >= w) {
                    ++sum;
                  }
                }
              }
            }
          }
        }
      }
      cout << sum << endl;
    }
  }
}
