#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-9;
long long solve(long long n) {
  long long ans = 0;
  while (n) {
    ans += n % 10;
    n /= 10;
  }
  return ans;
}
int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  while (1) {
    ans = ans * 10 + 9;
    if (ans > n) break;
  }
  ans /= 10;
  printf("%lld", solve(ans) + solve(n - ans));
  return 0;
}
