#include <bits/stdc++.h>
using namespace std;
void solve() {
  int k, digits = 0;
  long long ans;
  string s;
  cin >> s >> k;
  digits = s.length();
  if (k == 1) {
    ans = (digits - 1) * 9 + (s[0] - '0');
  } else {
    ans = 81 * (digits - 2) / 2.0 * (digits - 1);
  }
  cout << ans << endl;
}
signed main() {
  solve();
  return 0;
}
