#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main(){
    long long n,k;
    cin >> n;
    n++;
    k = int(log10(n));
    for(int i=0;i<k;i++)n/=10;
    cout << (n-1)+k*9 << endl;
    return 0;
}