#include <bits/stdc++.h>

using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define lson root<<1,l,(l+r)/2
#define rson root<<1|1,(l+r)/2+1,r
const int N = 1e5+5;
const ll INF = 1e18;
const ll p = 1e9+7;
int ans=0,a[20]={0};
ll n;
void dfs(int sum,int id,int flag)
{
	if(id<0){ans=max(ans,sum);return;}
	if(flag){
		if(sum+(id+1)*9>ans){
			dfs(sum+a[id],id-1,flag);
			for(int i=a[id]-1;i>=0;i--)dfs(sum+i,id-1,0);
		}
	}else{
		if(sum+(id+1)*9>ans){
			for(int i=9;i>=0;i--)dfs(sum+i,id-1,0);
		}
	}
}
int main()
{
	scanf("%lld",&n);
	ll tmp=n;int tot=0;
	while(tmp){a[tot++]=tmp%10;tmp/=10;}
	dfs(a[tot-1],tot-2,1);
	for(int i=a[tot-1]-1;i>=0;i--)dfs(i,tot-2,0);
	printf("%d\n",ans);
	return 0;
}
