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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

const ll MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-8;
const int MAXN = 1e7;

int main(int argc, char const *argv[]){
    string s;
    cin>>s;
    int len=(int)s.length();
    int ans=0;
    int t=0;
    for(int i=0;i<len;i++){
        int n=s[i]-'0';
        if(n>0){
            ans=max(ans,t+(n-1)+(len-1-i)*9);
        }
        t+=n;
    }
    ans=max(ans,t);
    cout<<ans<<endl;
    return 0;
}
