#include <cstdio>
using namespace std;
int f(long long x) {
int tmp = 0;
while (x != 0) {
tmp += x % 10;
x /= 10;
}
return tmp;
}
int main() {
long long c, a, b, isAllNine[12] = {9,99,999,9999,99999,999999,9999999,99999999,999999999,9999999999,99999999999,999999999999};
while (scanf("%lld", &c) != EOF) {
bool flag = true;
if (c % 2 == 0) {
for (int i = 0; i < 12; i++) {
if (c / 2 == isAllNine[i]) {
a = b = (c / 2);
flag = false;
break;
}
}
if (flag) {
a = c / 2 + 1;
b = a - 2;
}
}
else {
a = c / 2;
b = a + 1;
}
printf("%d\n", f(a) + f(b));
}
return 0;
}