#include <bits/stdc++.h>
using namespace std;
int sum_of_digit(long long int num) {
  int sum = 0;
  while (num != 0) {
    sum = sum + num % 10;
    num = num / 10;
  }
  return sum;
}
int main() {
  long long int n;
  cin >> n;
  if (n < 10) {
    cout << n;
    return 0;
  }
  long long int num2 = 0;
  int num = log10(n + 1);
  int sum = 0;
  for (int i = 0; i < num; i++) {
    sum += 9;
    num2 *= 10;
    num2 += 9;
  }
  cout << sum_of_digit(n - num2) + sum;
  return 0;
}
