#include <bits/stdc++.h>
using namespace std;
long long sum = 0;
long long a, b, cnt, n, i, j, gc = 1;
void mak(long long cn) {
  while (cn--) {
    a = a * 10 + 9;
  }
}
void sak(long long nn) {
  while (nn) {
    sum += nn % 10;
    nn = nn / 10;
  }
}
int main() {
  cin >> n;
  a = 0;
  cnt = log10(n);
  mak(cnt);
  b = n - a;
  sak(a);
  sak(b);
  cout << sum << endl;
  return 0;
}
