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

#define rnm ios::sync_with_stdio(false)
#define pb push_back;
typedef long long ll;
typedef long double ldb;
const int inf=0x7fffffff;
char a[25];

int main(){
	rnm;
	cin>>a;
	int l=strlen(a);
	int ans=0;
	ans+=a[0]-'0'-1;
	ans+=(l-1)*9;
	cout<<ans<<endl;
	return 0;
}