#include <bits/stdc++.h>
using namespace std;
long long n, ans;
int dig(long long x) { return (x != 0 ? dig(x / 10) + x % 10 : 0); }
void solve(long long curr) {
  if (curr > n) return;
  if (curr <= n && dig(curr) + dig(n - curr) > ans)
    ans = dig(curr) + dig(n - curr);
  solve(curr * 10 + 9);
  solve(curr * 10 + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  if (n < 19) {
    cout << n;
    return 0;
  }
  solve(0);
  cout << ans;
}
