#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long int inf64 = 1e18 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  string second;
  cin >> second;
  cin >> k;
  n = second.length();
  int pre[n];
  pre[0] = second[0] - '0';
  for (int i = 1; i < n; i++) pre[i] = pre[i - 1] + (second[i] - '0');
  int ans = 0;
  if (k == 1)
    ans = second[0] - '0' + 9 * (n - 1);
  else if (k == 2) {
    int i, j;
    int sr = second[0] - '0';
    for (int c1 = 1; c1 <= sr; c1++) {
      for (i = 1; i < n; i++) {
        int x = second[i] - '0';
        for (int c2 = 1; c2 < 10; c2++) {
          if (c1 == sr) {
            if (c2 <= x)
              ++ans;
            else {
              if (pre[i - 1] - pre[0] > 0) ++ans;
            }
          } else
            ++ans;
        }
      }
    }
    --n;
    ans += ((n * (n - 1)) / 2) * 9 * 9;
  } else {
    int sr = second[0] - '0';
    int i, j;
    for (int c1 = 1; c1 <= sr; c1++) {
      for (i = 1; i < n; i++) {
        int x = second[i] - '0';
        for (j = i + 1; j < n; j++) {
          int y = second[j] - '0';
          for (int c2 = 1; c2 < 10; c2++) {
            for (int c3 = 1; c3 < 10; c3++) {
              if (c1 == sr) {
                if (c2 < x)
                  ++ans;
                else if (c2 == x) {
                  bool active = (pre[i - 1] - pre[0] > 0);
                  if (active)
                    ++ans;
                  else {
                    if (pre[j - 1] - pre[i] > 0)
                      ++ans;
                    else if (c3 <= y)
                      ++ans;
                  }
                }
              } else
                ++ans;
            }
          }
        }
      }
    }
    --n;
    ans += ((n * (n - 1) * (n - 2)) / 6) * 9 * 9 * 9;
  }
  ans = max(ans, 0);
  cout << ans;
}
