#include <bits/stdc++.h>
using namespace std;
long long int foo(long long int x) {
  long long int sum = 0;
  while (x) {
    sum += (x % 10);
    x /= 10;
  }
  return sum;
}
int main() {
  int i, j, k;
  long long int n, m;
  scanf("%I64d", &n);
  if (n < 9) {
    printf("%I64d", n);
    return 0;
  }
  long long int x = 0;
  while (x * 10 + 9 <= n) x = x * 10 + 9;
  printf("%I64d", foo(x) + foo(n - x));
  return 0;
}
