#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  long long int ans;
  string s;
  cin >> s >> k;
  if (k == 2) {
    ans = 9 * (s.length() - 1) + s[0] - '0';
    cout << ans << '\n';
  } else {
  }
}
