#include <bits/stdc++.h>  
#define ll long long
using namespace std;  
#define N 100005  
int main ()
{
	ll n,num = 0,ans = 0,mm = 0;
	cin >> n;
	while(n)
	{
		ans += n%10ll;
		mm = n%10ll;
		n/=10ll;
		num++; 
	}
	ans = max(ans,(num-1)*9+mm-1);
	cout << ans << endl;
	return 0;
}