#include <bits/stdc++.h>
using namespace std;
int sum(long long n) {
  int res = 0;
  while (n != 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
int main() {
  long long n, temp;
  cin >> n;
  temp = n;
  string arr = "";
  int k = 0;
  while (temp != 0) {
    char ch = temp % 10 + 48;
    arr += ch;
    temp /= 10;
  }
  int first_dig = 0;
  long long half = 0;
  reverse(arr.begin(), arr.end());
  for (int i = 0; i < arr.size(); i++) {
    if (i == 0) {
      half = half * 10 + arr[i] - 48 - 1;
      first_dig = arr[i] - 48 - 1;
    } else {
      half = half * 10 + 9;
      first_dig += 9;
    }
  }
  long long sec_half = n - half;
  int sec_dig = sum(sec_half);
  cout << first_dig + sec_dig << endl;
}
