#include <bits/stdc++.h>
using namespace std;
int s(long long n) {
  long long ret = 0;
  while (n) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(32);
  long long n;
  cin >> n;
  long long prd = 1;
  while (prd * 10 <= n) prd *= 10;
  cout << s(prd - 1) + s(n - prd + 1) << endl;
  return 0;
}
