#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
  cin >> n;
  int c = log10(n);
  long long q = pow(10, c);
  q--;
  long long w = n - q;
  int ans = 0;
  while (w > 0) {
    ans += w % 10;
    w /= 10;
  }
  while (q > 0) {
    ans += q % 10;
    q /= 10;
  }
  cout << ans;
  return 0;
}
