#include <bits/stdc++.h>
using namespace std;

int main()
{
	string s,a;
	int c = 0, c2=0;
	cin >> s;
	a.push_back(s[0]-1);
	c += s[0]-1-'0';
	c2 += s[0]-'0';
	for (int i=1;i<s.size();++i) {
		c += 9;
		c2 += s[i]-'0';
	}
	cout << max(c, c2) << endl;
	return 0;
}