#include <bits/stdc++.h>
using namespace std;
long long int n;
int sumDigit(long long int n) {
  int ans = 0;
  while (n > 0) {
    ans += (n % 10);
    n /= 10;
  }
  return ans;
}
int main() {
  cin >> n;
  if (n <= 18) {
    cout << n << endl;
    return 0;
  }
  long long int now = 9;
  int ans = INT_MIN;
  while (now < n) {
    ans = max(ans, sumDigit(now) + sumDigit(n - now));
    now = now * 10 + 9;
  }
  cout << ans << endl;
}
