#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long t = 0, dp = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') dp = -1;
    c = getchar();
  }
  while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
  return t * dp;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + 48);
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void write_p(long long x) {
  write(x);
  putchar(' ');
}
inline long long Get(long long x) {
  int ret = 0;
  while (x) ret += x % 10, x /= 10;
  return ret;
}
int main() {
  long long n = read();
  long long tmp = 0, ans = 0;
  while (tmp <= n) {
    ans = max(ans, Get(tmp) + Get(n - tmp));
    tmp = tmp * 10 + 9;
  }
  cout << ans << endl;
}
