#include <bits/stdc++.h>
using namespace std;
struct mone {
  int value = -1;
};
const int N = 2e5 + 5;
bool comp(int x, int y) { return x > y; }
long long int sod(long long int n) {
  long long int ans = 0;
  while (n) ans += (n % 10), n /= 10;
  return ans;
}
long long int nod(long long int n) {
  long long int c = 0;
  while (n) c++, n /= 10;
  return c;
}
void solve() {
  long long int n;
  cin >> n;
  long long int temp = 0, t = 1;
  long long int k = n;
  while (n) {
    if (n / 10 == 0)
      temp += t * (n % 10 - 1);
    else
      temp += 9 * t;
    t *= 10;
    n /= 10;
  }
  cout << sod(temp) + sod(k - temp) << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
