#include <bits/stdc++.h>
template <class T>
void read(T &x) {
  int f = 0;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    f |= (ch == '-');
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
}
long long n, yhh, max, a, b;
long long gay(long long qwq) {
  long long ans = 0;
  while (qwq) ans += qwq % 10, qwq /= 10;
  return ans;
}
int main() {
  read(n);
  if (n <= 9) {
    printf("%I64d", n);
    return 0;
  }
  while (yhh < n) {
    yhh = yhh * 10 + 9;
    a = gay(yhh), b = gay(n - yhh);
    if (a + b > max) max = a + b;
  }
  printf("%I64d\n", max);
  return 0;
}
