#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const double PI = acos(-1);
const double ERR = 1e-10;
int cal(long long tmp) {
  int cnt = 0;
  while (tmp) {
    cnt += tmp % 10;
    tmp = tmp / 10;
  }
  return cnt;
}
int main() {
  long long n;
  scanf("%lld", &n);
  long long m = n;
  int pos = 0;
  while (n >= 10) {
    pos++;
    n = n / 10;
  }
  long long tmp = 0;
  for (int i = 0; i < pos; i++) {
    tmp = 1LL * tmp * 10 + 9;
  }
  long long tmp2 = m - tmp;
  printf("%d\n", 9 * pos + cal(tmp2));
  return 0;
}
