#include <bits/stdc++.h>
using namespace std;
long long a;
int main() {
  while (~scanf("%I64d", &a)) {
    int ans = 0;
    long long temp;
    long long weishu = 0;
    long long shabi = 1;
    while (shabi * 10 <= a) {
      shabi *= 10;
      weishu++;
    }
    temp = a - shabi + 1;
    a = shabi - 1;
    while (a) {
      int fok = a % 10;
      a /= 10;
      ans += fok;
    }
    while (temp) {
      int op = temp % 10;
      temp /= 10;
      ans += op;
    }
    cout << ans << endl;
  }
}
