#include <bits/stdc++.h>
const int N = 2e5 + 1024;
const int M = 2e5 + 1024;
using namespace std;
int so(long long a) {
  int ret = 0;
  while (a) {
    ret += a % 10;
    a /= 10;
  }
  return ret;
}
int main() {
  long long n;
  cin >> n;
  long long nn = n;
  int cnt = 0;
  while (nn) {
    cnt++;
    nn /= 10;
  }
  cnt--;
  long long ans = 0;
  while (cnt) {
    cnt--;
    ans *= 10;
    ans += 9;
  }
  long long b = n - ans;
  long long out = so(b) + so(ans);
  cout << out;
  return 0;
}
