#include <bits/stdc++.h>
using namespace std;
long long o[20] = {0,        9,         99,         999,
                   9999,     99999,     999999,     9999999,
                   99999999, 999999999, 9999999999, 99999999999};
int main() {
  long long n;
  cin >> n;
  long long len = 0;
  long long m = n;
  while (m) {
    len++;
    m /= 10;
  }
  if (len == 1) {
    cout << n << endl;
  } else {
    long long ans = 0;
    m = n - o[len - 1];
    while (m) {
      ans += m % 10;
      m /= 10;
    }
    ans += (len - 1) * 9;
    cout << ans << endl;
  }
  return 0;
}
