#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, ten, b;
  int k;
  ten = 1;
  cin >> n;
  m = n;
  int i = 0;
  for (i = 0; (m /= 10) != 0; i++) continue;
  for (k = 0; k < i; k++) ten *= 10;
  b = n - ten + 1;
  int sum = 9 * i;
  while (b != 0) {
    sum += b % 10;
    b /= 10;
  }
  printf("%d\n", sum);
  return 0;
}
