#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
bool isLowerCase(char c) { return (c >= 'a' && c <= 'z'); }
const string btos(bool ans) { return (ans ? "Yes" : "No"); }
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  int len = n.size();
  long long ans = 9 * (len - 1) + (n[0] - '0');
  cout << ans << endl;
  return 0;
}
