#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long m = n;
  long long xarisxi = 0;
  while (true) {
    if (n < 10) {
      break;
    }
    n = n / 10;
    xarisxi++;
  }
  if (xarisxi == 0) {
    cout << n;
    return 0;
  }
  long long temp = 9;
  for (long long i = 1; i < xarisxi; i++) {
    temp = temp * 10 + 9;
  }
  long long answer = xarisxi * 9;
  m = m - temp;
  while (true) {
    if (m < 10) {
      answer += m;
      break;
    }
    answer += m % 10;
    m = m / 10;
  }
  cout << answer << endl;
  return 0;
}
