#include <bits/stdc++.h>
using namespace std;
long long x;
int num[100], cnt, ans;
int main() {
  scanf("%lld", &x);
  while (x) {
    num[++cnt] = x % 10;
    x /= 10;
  }
  for (int i = 1; i <= cnt; i++) {
    if (num[i] == 9)
      ans += 9;
    else {
      int t = i + 1;
      while (!num[t] && t < cnt) t++;
      ans = ans + num[i];
      if (num[t]) {
        num[t]--;
        for (int j = i + 1; j < t; j++) num[j] = 9;
        ans = ans + 10;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
