#include <iostream>
#include <cstring>
#include <cstdio>
#include<string>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	long long n;
	cin >> n;
	n++;
	int s = 0;
	while (n > 9)
	{
		s += 9;
		n /= 10;
	}
	s += (n - 1);
	cout << s << endl;
	return 0;
}