#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long summ(long long a) {     long long ans = 0;     while (a) {       ans += a % 10;       a = a / 10;     }     return ans;   }   long long digit(int n) {     int count = 0;     while (n) {       n = n / 10;       count++;     }     return count;   }   long long sum(long long a) {     long long ans = 0;     while (a) {       ans += (a % 10);       a = a / 10;     }     return ans;   }   int main() {     long long n;     cin >> n;     long long a = n;     long long b;     long long count = 0;     while (a) {       b = a % 10;       a = a / 10;       count++;     }     count--;     b--;     b = b * pow(10, count);     long long c = 0;     for (int i = 0; i < count; i++) {       c = (10 * c) + 9;     }     b = b + c;     c = n - b;     cout << sum(b) + sum(c);     return 0;   }   