/*"-Aria on the Planets-"*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double D;
typedef pair<int,int> Pii;
#define mp(a,b) make_pair(a,b)
#define fir first
#define sec second
inline int min(int _a,int _b){return _a<_b?_a:_b;}
inline int max(int _a,int _b){return _a>_b?_a:_b;}
template<class _T>inline void rd(_T &_a){int _f=0,_ch=getchar();_a=0;while(_ch<'0'||_ch>'9'){if(_ch=='-')_f=1;_ch=getchar();}while(_ch>='0'&&_ch<='9')_a=(_a<<1)+(_a<<3)+_ch-'0',_ch=getchar();if(_f)_a=-_a;}
const int inf=0x3f3f3f3f;
const D eps=1e-8;
int main(){
	//clock_t start=clock();
	//freopen("ttt.in","r",stdin);
	//freopen("ttt.out","w",stdout);
	LL n;int x=0,f=0,a;rd(n);
	while(n){
		a=n%10;
		if(n%10!=9)f=1;
		x++;
		n/=10;
	}
	printf("%d",a+x*9-9-f);
	//printf("\n%dms",(int)((D)(clock()-start)/CLOCKS_PER_SEC*1000));
	return 0;
}
