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