#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
	string s;
	cin>>s;
	int len=s.length();
	LL a=(int)(s[0]-'0')-1+(len-1)*9;
	cout<<a<<endl;
 	return 0;
}
