#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
const long long INF = 1e12;
int solve(long long x) {
  int res = 0;
  while (x) {
    res += (x % 10);
    x /= 10;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  long long n;
  while (cin >> n) {
    long long tmp = 0, b = 0;
    while (1) {
      tmp = tmp * 10 + 9;
      if (tmp > n) break;
      b = tmp;
    }
    cout << solve(b) + solve(n - b) << endl;
  }
  return 0;
}
