#include<iostream>
using namespace std;
int main(){
	long long s;
	cin>>s;
	int ans=0;
	bool nine=0;
	while(s>=10){
		if(s%10<9)nine=1;
		s/=10;
		ans+=9;
	}
	ans+=s;
	if(nine)ans--;
	cout<<ans<<endl;
}