#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int a = 0, f, s2 = 0, t, b, n;
  cin >> n;
  t = n;
  unsigned long long int d = 0;
  while (n != 0) {
    f = n % 10;
    n = n / 10;
    if (n == 0) {
      a = a + pow(10, d) * (f - 1);
    } else {
      a = a + pow(10, d) * 9;
      d++;
    }
  }
  unsigned long long int s1 = d * 9 + f - 1;
  b = t - a;
  while (b > 0) {
    s2 = s2 + b % 10;
    b = b / 10;
  }
  unsigned long long int s = s1 + s2;
  cout << s;
}
