#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long n = N;
  long long logi = 0;
  while (n >= 10) {
    n /= 10;
    logi++;
  }
  long long zahl = 0;
  for (int i = 0; i < logi; i++) {
    zahl *= 10;
    zahl += 9;
  }
  N -= zahl;
  long long QS = 0;
  string S = to_string(N);
  for (long long i = 0; i < (long long)S.length(); i++) {
    QS += S[i] - '0';
  }
  cout << logi * 9 + QS;
}
