#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int inf = 1e9 + 9;
const long long INF = 1e18 + 3;
const long double eps = 1e-9;
const long double PI = acos(-1.0);
const long double E = 2.71828182845904523536;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, ans = 0;
  int x = 0, sum = 0, f = 0;
  cin >> n;
  while (ans * 10 + 9 <= n) {
    ans = ans * 10 + 9;
    sum += 9;
  }
  n -= ans;
  while (n) {
    sum += n % 10;
    n /= 10;
  }
  cout << sum << endl;
  return 0;
}
