#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char c = getchar();
  long long kkk = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    kkk = (kkk << 3) + (kkk << 1) + (c - '0'), c = getchar();
  return kkk;
}
long long n;
inline int fun(long long k) {
  int ans = 0;
  while (k > 0) {
    ans += k % 10;
    k /= 10;
  }
  return ans;
}
int main() {
  n = read();
  long long a = 0;
  while (a <= n) a = a * 10 + 9;
  a = a / 10;
  long long b = n - a;
  cout << fun(a) + fun(b);
  return 0;
}
