#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#define ll long long
using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin>>s;
	int l=s.length();
	int i=l-1;
	for (;i>=0;i--)
		if (s[l]!='9') break;
	if (i==-1) cout<<l*9<<endl;
	else if (i==0) cout<<(l-1)*9+s[0]-'0';
	else cout<<(l-1)*9+s[0]-'0'-1;
	return 0;
}