#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x = 0, ans = 0;
  scanf("%I64d", &n);
  while (x <= n) {
    x = x * 10 + 9;
    ans += 9;
  }
  x /= 10;
  ans -= 9;
  n -= x;
  while (n) {
    ans += n % 10;
    n /= 10;
  }
  printf("%I64d\n", ans);
  return 0;
}
