#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 9e18;
const int inf = 2147483647;
long long phi(long long n) {
  long long ans = n;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans = ans / i * (i - 1);
      while (n % i == 0) n /= i;
    }
  }
  if (n > 1) ans = ans / n * (n - 1);
  return ans;
}
long long qpow(long long a, long long b, long long mod) {
  long long r = 1;
  for (; b; b >>= 1) {
    if (b & 1) r = (r * a) % mod;
    a = (a * a) % mod;
  }
  return r;
}
long long C(int n, int m) {
  if (m < n - m) m = n - m;
  long long ans = 1;
  for (int i = m + 1; i <= n; i++) ans *= i;
  for (int i = 1; i <= n - m; i++) ans /= i;
  return ans;
}
const int N = 2e3 + 5;
void work() {
  long long n;
  cin >> n;
  long long m = n;
  int cnt = 0;
  long long a;
  while (m) {
    if (m < 10) a = m;
    cnt++, m /= 10;
  }
  if (cnt) cnt--;
  int t = cnt;
  long long ta = a;
  while (cnt--) {
    a *= 10;
    a += 9;
  }
  if (a > n) {
    ta--;
    while (t--) {
      ta *= 10;
      ta += 9;
    }
    a = ta;
  }
  long long b = n - a;
  int ans = 0;
  while (a) {
    ans += a % 10;
    a /= 10;
  }
  while (b) {
    ans += b % 10;
    b /= 10;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  work();
  return 0;
}
