#include <bits/stdc++.h>
using namespace std;
int main() {
  int A[15], sum = 0;
  string s;
  cin >> s;
  sum += 9 * (s.length() - 1);
  for (int i = 1; i <= s.length(); i++) A[i] = s[i - 1] - 48;
  for (int i = s.length(); i >= 2; i--) {
    if (A[i] < 9) {
      A[i] = A[i] + 10 - 9;
      A[i - 1] -= 1;
      sum += A[i];
    } else
      A[i] = 0;
  }
  cout << sum + A[1];
  return 0;
}
