#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
long long int sumOfDigits(long long int n) {
  long long int sum = 0;
  while (n) {
    int x = n % 10;
    sum = sum + x;
    n = n / 10;
  }
  return sum;
}
long long int binaryExponentiation(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return binaryExponentiation(x * x, n / 2);
  else
    return x * binaryExponentiation(x * x, (n - 1) / 2);
}
int main() {
  long long n, a, b;
  cin >> n;
  long long m = n, k = 9;
  while (m >= k) {
    k = k * 10 + 9;
  }
  k /= 10;
  a = k;
  b = n - k;
  long long sum = 0;
  while (a) {
    sum += a % 10;
    a /= 10;
  }
  while (b) {
    sum += b % 10;
    b /= 10;
  }
  cout << sum << endl;
  return 0;
}
