#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
vector<int> cs;
int res = 0;
int main() {
  cin >> n;
  long long tmp = n;
  while (tmp > 0) {
    cs.push_back(tmp % 10);
    tmp /= 10;
  }
  long long a = 0;
  long long base = 1;
  for (int i = 0; i < cs.size() - 1; ++i) {
    a += 9 * base;
    base *= 10;
    res += 9;
  }
  a += (cs[cs.size() - 1] - 1) * base;
  res += (cs[cs.size() - 1] - 1);
  long long b = n - a;
  while (b > 0) {
    res += b % 10;
    b /= 10;
  }
  cout << res;
  return 0;
}
