#include <bits/stdc++.h>
using namespace std;
long long n, x = 0, res = 0;
long long rd();
void wrt(long long);
long long sum(long long x) {
  long long s = 0;
  while (x) s += x % 10, x /= 10;
  return s;
}
int main() {
  cin >> n;
  while (x <= n) res = max(res, sum(x) + sum(n - x)), x = x * 10 + 9;
  cout << res;
  return 0;
}
long long rd() {
  static long long s, x, c;
  s = 1;
  x = 0;
  c = getchar();
  while (c != '-' && !isdigit(c)) c = getchar();
  if (c == '-') s = -1, c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0', c = getchar();
  return s * x;
}
void wrt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + '0');
  else
    wrt(x / 10), putchar(x % 10 + '0');
}
