#include <iostream>
#include <string>

using namespace std;

int main(){
    string N;
    cin >> N;
    int sum = 0;
    for(auto c : N) sum += c - '0';
    cout << max(sum, (int)((N.length() - 1)*9 + N[0] - '1')) << "\n";
}