#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0LL) return b;
  if (b == 0LL) return a;
  return gcd(b, a % b);
}
int dp[2][20];
void solve() {
  string s;
  cin >> s;
  memset(dp, -1 * 1000000007LL, sizeof(dp));
  dp[0][s.size()] = 0;
  for (int i = s.size() - 1; i >= 0; i--)
    for (int j = 0; j < 2; j++)
      for (int dig1 = 0; dig1 < 10; dig1++)
        for (int dig2 = 0; dig2 < 10; dig2++)
          if ((dig1 + dig2 + j) % 10 == s[i] - '0')
            dp[(dig1 + dig2 + j) / 10][i] =
                max(dp[(dig1 + dig2 + j) / 10][i], dp[j][i + 1] + dig1 + dig2);
  cout << dp[0][0] << "\n";
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  clock_t clk = clock();
  int t = 1;
  for (int tests = 1; tests <= t; tests++) {
    solve();
  }
  clk = clock() - clk;
  cerr << "Time Elapsed: " << fixed << setprecision(10)
       << ((long double)clk) / CLOCKS_PER_SEC << "\n";
  return 0;
}
