#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char c[20];
int i,n,t1,t2;

int main()
{
	scanf("%s",c+1);
	n=strlen(c+1);
	for (i=1;i<=n;i++)
		t1=t1+c[i]-48;
	t2=c[1]-49+(n-1)*9;
	printf("%d",max(t1,t2));
	return 0;
}
