#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long temp = n;
  long long c = 0;
  while (temp != 0) {
    temp /= 10;
    c++;
  }
  long long ans;
  long long num1;
  num1 = ((n / (long long)pow(10, c - 1)) - 1);
  ans = num1 + (c - 1) * 9;
  long long nm1 = 0;
  for (long long i = 0; i <= c - 2; i++) nm1 += 9 * (long long)(pow(10, i));
  nm1 += num1 * (long long)(pow(10, c - 1));
  long long nm2 = n - nm1;
  while (nm2 != 0) {
    ans += nm2 % 10;
    nm2 /= 10;
  }
  cout << ans;
  return 0;
}
