#include <bits/stdc++.h>
using namespace std;
string s;
int cnt;
int getdeal(long long c) {
  int ret = 0;
  while (c) {
    ret += c % 10;
    c /= 10;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long temp = 0;
  while (temp * 10 + 9 <= n) {
    temp = temp * 10 + 9;
  }
  cout << getdeal(temp) + getdeal(n - temp);
}
