#include <bits/stdc++.h>
using namespace std;
long long cal(long long x) {
  long long sum = 0;
  while (x) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
long long pre[100];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  pre[1] = 9;
  for (long long i = 2; i <= 15; ++i) {
    pre[i] = pre[i - 1] * 10 + 9;
  }
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  long long Max = 0;
  Max = max(Max, cal(n));
  Max = max(Max, cal(n - 1) + cal(1));
  long long temp = n;
  long long wei = 0;
  while (temp) {
    temp /= 10;
    ++wei;
  }
  if (wei == 1) {
    cout << Max << endl;
  } else {
    for (long long i = 1; i <= 15; i++) {
      if (n > pre[i]) {
        Max = max(Max, cal(pre[i]) + cal(n - pre[i]));
      }
    }
    cout << Max << endl;
  }
  return 0;
}
