#include <bits/stdc++.h>
using namespace std;
template <class A>
void p(A a) {
  cout << (a) << endl;
}
template <class A, class B>
void p(A a, B b) {
  cout << a << " ";
  p(b);
}
template <class A, class B, class C>
void p(A a, B b, C c) {
  cout << a << " ";
  p(b, c);
}
template <class A, class B, class C, class D>
void p(A a, B b, C c, D d) {
  cout << a << " ";
  p(b, c, d);
}
int INF = numeric_limits<int>::max();
int main(void) {
  double N;
  cin >> N;
  int K;
  cin >> K;
  int d = log10(N);
  int res;
  if (K == 1) {
    res = 9 * d + N / pow(10, d);
  } else if (K == 2) {
  } else {
  }
  p(res);
  return 0;
}
