#include <iostream>
#include<cstdio>
using namespace std;

int main()
{
	long long num;
	cin>>num;
	int tail=0,a;
	for(tail=0; num; tail++){
		a=num%10;
		num/=10;
	}
	int ans=9*(tail-1)+(a-1);
	printf("%d\n",ans);
    return 0;
}
