#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, c, d;
  cin >> a;
  int col = 0;
  long long a1 = a;
  vector<int> b(0);
  while (a > 0) {
    b.push_back(a % 10);
    a = a / 10;
    col++;
  }
  c = b[col - 1] * pow(10, col - 1) - 1;
  d = a1 - c;
  int col1 = 0;
  vector<int> e(0);
  while (c > 0) {
    e.push_back(c % 10);
    c = c / 10;
    col1++;
  }
  vector<int> f(0);
  int col2 = 0;
  while (d > 0) {
    f.push_back(d % 10);
    d = d / 10;
    col2++;
  }
  int s1 = 0;
  int s2 = 0;
  while (col1 > 0) {
    s1 = s1 + e[col1 - 1];
    col1--;
  }
  while (col2 > 0) {
    s2 = s2 + f[col2 - 1];
    col2--;
  }
  cout << s1 + s2;
  return 0;
}
