#include <bits/stdc++.h>
int main() {
  long long int n, m, i = 0, A[20] = {0}, j, sum1 = 0, k = 1, p = 0, q,
                      sum2 = 0, B[20] = {0};
  scanf("%I64d", &n);
  m = n;
  while (m != 0) {
    A[i] = m % 10;
    m = (m - A[i]) / 10;
    i = i + 1;
  }
  A[i - 1] = A[i - 1] - 1;
  sum1 = sum1 + A[i - 1];
  for (j = 0; j < i - 1; j++) {
    A[j] = 9;
    p = p + A[j] * k;
    sum1 = sum1 + A[j];
    k = k * 10;
  }
  p = p + A[i - 1] * k;
  q = n - p;
  i = 0;
  while (q != 0) {
    B[i] = q % 10;
    sum2 = sum2 + B[i];
    q = (q - B[i]) / 10;
    i = i + 1;
  }
  printf("%I64d", sum1 + sum2);
}
