#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  long long num = 0;
  while (num * 10 + 9 < n) {
    num = num * 10 + 9;
    ans += 9;
  }
  n -= num;
  while (n) {
    ans += n % 10;
    n /= 10;
  }
  cout << ans << endl;
}
