#include<cstdio>
using namespace std;
typedef long long ll;
ll n,ans=0,ok=1;
int main()
{
	scanf("%lld",&n);
	while(n/10)
	{
		ans+=9;
		if(n%10<9)ok=0;
		n/=10;
	}
	ans+=n;
	if(!ok)ans--;
	printf("%lld\n",ans);
	return 0;
}