#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long n;
long long a, b;
int countdigits(long long x) {
  int ret = 0;
  while (x) {
    ret = ret + 1;
    ;
    x = x / 10;
  }
  return ret;
}
int sumdigits(long long x) {
  int ret = 0;
  while (x) {
    ret = ret + x % 10;
    x = x / 10;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int dem = countdigits(n);
  while (dem > 1) {
    a = a * 10 + 9;
    dem = dem - 1;
  }
  b = n - a;
  cout << sumdigits(a) + sumdigits(b);
}
