#include <bits/stdc++.h>
using namespace std;
long long n;
int S(long long x) {
  int ans = 0;
  while (x) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}
int f[14][0];
int main() {
  cin >> n;
  long long sum = 0;
  while (sum * 10 + 9 <= n) sum = sum * 10 + 9;
  n -= sum;
  cout << S(sum) + S(n) << "\n";
}
