#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin>>n;
    ll ans=0;
    ll ct=0;
    while(n>=10){
        ans+=n%10;
        n/=10;
        ct++;
    }
    ans+=n;
    cout<<max(ans, ct*9+n-1)<<endl;
    return 0;
}