#include <bits/stdc++.h>
using namespace std;
int s(long long n) {
  int ans = 0;
  while (n) {
    ans += n % 10;
    n /= 10;
  }
  return ans;
}
int brute(long long n) {
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (s(i) + s(n - i) > ans) ans = s(i) + s(n - i);
  }
  return ans;
}
long long near(long long n) {
  long long n1 = n;
  while (n1 / 10) n1 /= 10;
  long long ans = n1 - 1;
  while (n / 10) {
    ans = ans * 10 + 9;
    n /= 10;
  }
  return ans;
}
int main() {
  for (int i = 0; i < 1000; i++) {
    long long n;
    cin >> n;
    long long a, b;
    a = near(n);
    b = n - a;
    cout << s(a) + s(b);
    return 0;
  }
  return 0;
}
