#include <bits/stdc++.h>
using namespace std;
long long n, digit, a, b, moda, modb;
int main() {
  cin >> n;
  b = n;
  while (n > 0) {
    n /= 10;
    digit++;
  }
  while (digit - 1 > 0) {
    a *= 10;
    a += 9;
    digit--;
  }
  b = b - a;
  while (b > 0) {
    modb += b % 10;
    b /= 10;
  }
  while (a > 0) {
    moda += a % 10;
    a /= 10;
  }
  cout << moda + modb << endl;
}
