#include <bits/stdc++.h>
using namespace std;
long long n;
int f(long long x) {
  int tmp = 0;
  while (x) tmp += x % 10, x /= 10;
  return tmp;
}
int main() {
  cin >> n;
  long long s = 0;
  while (s * 10 + 9 <= n) s = s * 10 + 9;
  cout << f(s) + f(n - s);
  return 0;
}
