#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
int main() {
  iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  long long ans = 0, ct = 1;
  while (ct * 10LL - 1 <= n) {
    ct *= 10LL;
    ans += 9LL;
  }
  long long kp = n - ct + 1;
  while (kp) {
    ans += kp % 10;
    kp /= 10;
  }
  cout << ans;
  return 0;
}
