#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f3f3f3f3f
#define MAXN 500010
const int MOD=1e9+7;
typedef long long ll;
using namespace std;
char s[1010];
int main()
{
	while(cin >> s){
		int len = strlen(s), sum = 0;
		if(s[0] == '1'){
			sum = (len-1)*9;
		}
		else{
			sum += s[0]-'0'-1;
			for(int i = 1; i < len; i++){
				sum += 9;
			}
		}
		cout << sum << endl;
	}
	return 0;
}