#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0)
    return power(a * a, b / 2);
  else
    return power(a, b - 1) * a;
}
long long n, res;
int main() {
  scanf("%I64d", &n);
  if (n == 1) {
    printf("%d\n", 1);
    return 0;
  }
  res = n / 2;
  long long x = (floor(log10(res)));
  long long f = res / (power(10, x));
  res = f;
  while (x--) {
    f *= 10;
    f += 9;
    res += 9;
  }
  long long v = (n - f);
  while (v) {
    res += v % 10;
    v /= 10;
  }
  printf("%I64d\n", res);
}
