#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  ;
  long long n;
  std::cin >> n;
  long long tmp = n;
  int ct = 0, ls;
  while (tmp > 0) {
    ls = tmp % 10;
    tmp = tmp / 10;
    ct++;
  }
  long long gg = 0;
  gg = gg * 10 + (ls - 1);
  for (int i = 2; i <= ct; i++) {
    gg = gg * 10LL + 9LL;
  }
  long long no2 = n - gg;
  int s2 = 0;
  while (no2 > 0) {
    s2 += (no2 % 10);
    no2 /= 10;
  }
  std::cout << s2 + (9 * (ct - 1) + ls - 1) << endl;
  return 0;
}
