#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, b;
  cin >> n;
  long long int cnt = 0, x = n;
  while (x > 0) {
    cnt++;
    x = x / 10;
  }
  long long int a = 0, sum = 0;
  cnt--;
  while (cnt--) {
    a = a * 10 + 9;
    sum += 9;
  }
  b = n - a;
  while (b > 0) {
    sum += b % 10;
    b = b / 10;
  }
  cout << sum;
  return 0;
}
