#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) { return c - '0'; }
int main() {
  string n;
  int k;
  int ans = 0;
  vector<int> dp1[4];
  vector<int> dp2[4];
  cin >> n;
  cin >> k;
  for (int i = 0; i < 4; i++) {
    dp1[i].push_back(0);
    dp2[i].push_back(0);
  }
  for (int i = int(n.size() - 1); i >= 0; i--) {
    int a = ctoi(n[i]);
    int b = 9 - a;
    int dp11 = dp1[1].back();
    int dp12 = dp1[2].back();
    int dp13 = dp1[3].back();
    int dp21 = dp2[1].back();
    int dp22 = dp2[2].back();
    int dp23 = dp2[3].back();
    dp1[1].push_back(dp11 + min(a, 1) * dp21 + a);
    dp1[2].push_back(dp12 + min(a, 1) * dp22 + a * dp11 + max(a - 1, 0) * dp21);
    dp1[3].push_back(dp13 + min(a, 1) * dp23 + a * dp12 + max(a - 1, 0) * dp22);
    dp2[1].push_back((1 - min(a, 1)) * dp21 + b);
    dp2[2].push_back((1 - min(a, 1)) * dp22 + b * (dp11 + dp21) + dp21);
    dp2[3].push_back((1 - min(a, 1)) * dp23 + b * (dp12 + dp22) + dp22);
  }
  cout << dp1[k].back() << endl;
  return 0;
}
