# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<vector>
# include<cstdio>
# include<cstdlib>
# include<map>
# include<deque>

# define deb(x) printf("# x=%d\n",x)
# define deb_d(x) printf("# x=%lf\n",x)
# define ccout(x) printf("%d\n",x)

typedef long long ll;

using namespace std;

string s;

bool check(){
	int sum=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='9')
			sum++;
	}
	return sum==s.length();
}

int main(void){
	while(cin>>s){
		if(s.length()==1){
			printf("%c\n",s[0]);
			continue;
		}
		if(check()){
			printf("%d\n",s.length()*9);
			continue;			
		}
		int ans=0;	
		ans=(s.length()-1)*9;
		ans+=s[0]-'0'-1;
		printf("%d\n",ans);
	}
	return 0;
}