#include <bits/stdc++.h>
using namespace std;
int main(){
  long n,a;
  cin >> n;
  long x = n,k=0,l=0;
  while(x>0){
      a = x%10;
      x /= 10;
      k++;
  }
  if((n+1)%long(pow(10,k-1))==0) cout << 9*(k-1)+a << endl;
  else cout << 9*(k-1)+a-1 << endl;
}