#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
 
using namespace std;
int sum(string n){
    int sum=0;
    for (int i=0; i<n.length(); ++i) {
        sum+=n[i]-'0';
    }
    return sum;
}
 
int main(){
    string n;
    cin>>n; 
     
    int maxx = 0;
    for (int i = n.length()-1; i>=0; --i) {
        string nn = n;
        if(i-1>=0 && n[i-1]!='0'){
            for (int j = n.length()-1; j>=i; j--)
                nn[j]='9';
            nn[i-1]=(char)(nn[i-1]-1);
        }
        int s = sum(nn);
        maxx = maxx > s ? s : maxx;
    }
    cout<<maxx<<endl;
    return 0;
}