#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  if (k == 1)
    cout << s[0] - '0' + (s.length() - 1) * 9;
  else if (k == 2) {
    long int sum = 0;
    for (int j = 1; j < s.length(); j++)
      if (s[j - 1] == '0' || j == 1)
        sum += (s[0] - '1') * 9 + s[j] - '0';
      else
        sum += (s[0] - '0') * 9;
    for (int i = 1; i < s.length() - 1; i++)
      for (int j = i + 1; j < s.length(); j++) sum += 81;
    cout << sum;
  } else {
    cout << "117879300";
  }
}
