#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, t;
  long long x = 0, y;
  int ans = 0, len = 0;
  cin >> n;
  t = n;
  while (n > 0) {
    len++;
    n = n / 10;
  }
  ans = ans + (len - 1) * 9;
  for (int i = 1; i <= len - 1; i++) {
    x = x * 10 + 9;
  }
  y = t - x;
  while (y > 0) {
    ans += y % 10;
    y = y / 10;
  }
  cout << ans << endl;
  return 0;
}
