#include <bits/stdc++.h>
using namespace std;
long long n;
long long fun(long long x) {
  int res = 0;
  while (x) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
int get_len(long long x) {
  int res = 0;
  while (x) {
    res++;
    x /= 10;
  }
  return res;
}
long long fastpow(long long base, long long times) {
  long long res = 1;
  while (times--) {
    res *= base;
  }
  return res;
}
int main() {
  scanf("%lld", &n);
  long long l = get_len(n);
  long long tmp = fastpow(10, l - 1);
  long long tmp1 = n % tmp;
  printf("%lld\n", fun(tmp1 + 1) + fun(n - tmp1 - 1));
  return 0;
}
