#include<iostream>  
#include<cstring>  
#include<cstdlib>  
#include<algorithm>  
#include<cmath>  
#include<cstdio>  
#define ll long long   
using namespace std;  
inline int read()  
{  
    int x=0,f=1;char s=getchar();  
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s<='9'&&s>='0'){x=x*10+s-'0';s=getchar();}  
    return x*f;  
}  
int main()  
{  
    char ch[50];  
    scanf("%s",ch);  
    bool flag=true;  
    for(int i=1;i<strlen(ch);i++)  
        if(ch[i]!='9')flag=false;  
    if(flag)printf("%d\n",(strlen(ch)-1)*9+ch[0]-'0');else  
        printf("%d\n",(strlen(ch)-1)*9+ch[0]-'0'-1);  
    return 0;  
}  