#include <bits/stdc++.h>
using namespace std;
const int SZ = 100010;
const int INF = 1e9 + 10;
const int mod = 10007;
const long double eps = 1e-8;
long long read() {
  long long n = 0;
  char a = getchar();
  bool flag = 0;
  while (a > '9' || a < '0') {
    if (a == '-') flag = 1;
    a = getchar();
  }
  while (a <= '9' && a >= '0') {
    n = n * 10 + a - '0', a = getchar();
  }
  if (flag) n = -n;
  return n;
}
int S(long long x) {
  int ans = 0;
  while (x) ans += x % 10, x /= 10;
  return ans;
}
int main() {
  long long n = read();
  long long t = 1, b = 0;
  while (t <= n) t *= 10, b++;
  int ans2 = (b - 1) * 9 + S(n - t / 10 + 1);
  cout << ans2 << endl;
  return 0;
}
