#include <bits/stdc++.h>
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long cnt = 1;
  long long now = 10;
  while (now <= N) {
    now *= 10;
    cnt++;
  }
  long long ans = (cnt - 1) * 9;
  long long n = cnt - 1;
  long long sum = 0;
  while (n--) {
    sum = sum * 10 + 9;
  }
  sum = N - sum;
  while (sum) {
    ans += sum % 10;
    sum /= 10;
  }
  cout << ans << endl;
  return 0;
}
