#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long oo = 1e18;
const long long N = 2e6 + 5;
long long a[N];
int main() {
  long long i, j, k;
  long long n, m, t;
  cin >> n;
  if (n <= 9)
    cout << n << endl;
  else {
    k = 9;
    while (1) {
      if (k > n) {
        k /= 10;
        break;
      }
      k = k * 10 + 9;
    }
    m = k;
    long long ans = 0;
    while (m) ans += m % 10, m /= 10;
    m = n - k;
    while (m) ans += m % 10, m /= 10;
    cout << ans << endl;
  }
  return 0;
}
