#include <bits/stdc++.h>
using namespace std;
long long dem, n, t[10000], f[10000], a1, b1, kq;
int main() {
  cin >> n;
  long long k = n;
  while (n) {
    t[++dem] = n % 10;
    n /= 10;
  }
  a1 = t[dem] - 1;
  for (int i = dem - 1; i >= 1; i--) {
    f[i] = 9;
    a1 = a1 * 10 + 9;
  }
  b1 = k - a1;
  while (a1) {
    kq += a1 % 10;
    a1 /= 10;
  }
  while (b1) {
    kq += b1 % 10;
    b1 /= 10;
  }
  cout << kq;
}
