#include <bits/stdc++.h>
using namespace std;
long long int num[200005];
int main(void) {
  long long int sum = 0, range = 0, ceiling;
  double ans = 0.0, d;
  long long int m, n, o, i, j, k = 0, money;
  long long int a, a1 = 0, a2 = 0, a3 = 0, ar, as, at1;
  char c;
  a = a1 = a2 = a3 = 0;
  string s, s1, s2;
  cin >> s;
  cin >> k;
  if (k == 1) {
    sum = (s.size() - 1) * 9;
    sum += s[0] - '0';
  }
  cout << sum;
  return 0;
}
