#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  int a, ans;
  cin >> N >> K;
  if (K == 1) {
    a = (int)log10(N);
    ans = a * 9 + N / pow(10, a);
  }
  if (K == 2) {
    N /= 10;
    a = (int)log10(N);
    ans = a * 9 + N / pow(10, a);
  }
  cout << ans << endl;
}
