#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
ll n;
int main()
{
    scanf("%lld",&n);
    int cnt=0;
    while(n>=10){
        cnt+=9;
        n/=10;
    }
    cnt+=n;
    cnt--;
    printf("%d\n",cnt);

    return 0;
}
