#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int len = s.length();
  int k;
  cin >> k;
  long long ans = 0;
  int a[5000] = {0};
  for (int m = 0; m < len; ++m) {
    a[m + 1] = a[m];
    if (s[m] != '0') a[m + 1]++;
  }
  if (k == 1) {
    ans += s[0] - '0';
    for (int i = 1; i < len; ++i) {
      if (s[i] == '0')
        ans += 9;
      else
        ans += s[i] - '0';
    }
    cout << ans;
    return 0;
  }
  if (k == 2) {
    for (int i = 0; i < len; ++i) {
      for (int j = i + 1; j < len; ++j) {
        if (i == 0) {
          if (a[j] == 1)
            ans += s[j] - '0' + (s[i] - '0' - 1) * 9;
          else if (a[j] > 1)
            ans += (s[i] - '0') * 9;
        } else
          ans += 81;
      }
    }
  }
  if (k == 3) {
    for (int i = 0; i < len; ++i) {
      for (int j = i + 1; j < len; ++j) {
        for (int l = j + 1; l < len; ++l) {
          if (s[i] != '0' && s[j] != '0' && s[l] != '0') {
            long long tmp = 0;
            if (i == 0) {
              if (a[j] == 1)
                tmp = s[j] - '0' + (s[i] - '0' - 1) * 9;
              else if (a[j] > 1)
                tmp = (s[i] - '0') * 9;
              if (a[l] == 2)
                tmp = s[l] - '0' + (tmp - 1) * 9;
              else if (a[l] > 2)
                tmp *= 9;
            } else
              tmp = 9 * 9 * 9;
            ans += tmp;
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
