#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') {
      f = -1;
    }
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long get(long long n) {
  long long res = 0;
  while (n) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
signed main() {
  long long n = read();
  long long a = 0;
  while (10 * a + 9 <= n) {
    a = 10 * a + 9;
  }
  cout << get(a) + get(n - a) << endl;
  return 0;
}
