#include <bits/stdc++.h>
long long max(long long a, long long b) { return a > b ? a : b; }
int main() {
  long long n;
  scanf("%I64d", &n);
  long long ans = -1;
  long long len = 0, count = n;
  while (count) {
    len++;
    count /= 10;
  }
  long long p = 1;
  for (long long i = 1; i < len; i++) p *= 10;
  for (long long a = p - 1; a <= (p - 1) * 10 + 9 && a <= n; a += p) {
    long long b = n - a;
    long long sum = 0;
    while (b) {
      sum += b % 10;
      b /= 10;
    }
    ans = max(ans, sum + (len - 1) * 9 + a / p);
  }
  printf("%I64d", ans);
  return 0;
}
