#include <bits/stdc++.h>
using namespace std;
long long n, r, m, k, i, t, sum1, sum2;
int main() {
  cin >> n;
  k = log10(n);
  t = n;
  while (t) {
    r = t % 10;
    t /= 10;
  }
  for (i = 1; i <= k; i++) m = m * 10 + 9;
  r--;
  sum1 = k * 9 + r;
  r = r * pow(10, k) + m;
  t = n - r;
  while (t) {
    sum2 += t % 10;
    t /= 10;
  }
  cout << sum1 + sum2;
}
