#include<cstdio>
#include<cstring>
char s[100];
int ans,flag;
int main()
{
	scanf("%s",s);
	ans=9*(strlen(s)-1)+s[0]-'0'-1;
	flag=1;
	for (int i=1;i<strlen(s);i++) if (s[i]!='9') flag=0;
	printf("%d\n",ans+flag);
	return 0;
}