#include<bits/stdc++.h>
using namespace std;
string s;

int main(){
  cin >> s;
  bool flg = true;
  for(int i=1;i<s.size();i++) {if (s[i]!='9') flg=false;}
  int ans = (s[0]-'1') + 9 * (s.size()-1) + (flg);
  cout << ans << endl;
  return 0;
}