#include <bits/stdc++.h>
using namespace std;
int sum(long long int n) {
  int s = 0;
  while (n) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
int main() {
  long long int ans = 0, n, x;
  string s, p;
  cin >> s;
  stringstream second(s);
  second >> n;
  int k = s.size() - 1;
  ans = k * 9;
  p += '0';
  for (int i = 0; i < k; i++) p += '9';
  stringstream zz(p);
  zz >> x;
  n -= x;
  cout << ans + sum(n) << endl;
  return 0;
}
