#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  if (n <= 10) {
    cout << n << endl;
  } else {
    long long int x = n;
    long long int count = 0;
    while (n > 0) {
      int rem = n % 10;
      count++;
      n = n / 10;
    }
    long long int a = 0;
    for (int i = 0; i < count - 1; i++) {
      a = a * 10 + 9;
    }
    long long int b = x - a, sum1 = 0;
    while (a > 0) {
      sum1 += a % 10;
      a = a / 10;
    }
    long long sum2 = 0;
    while (b > 0) {
      sum1 += b % 10;
      b = b / 10;
    }
    cout << sum1 + sum2 << endl;
  }
  return 0;
}
