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