function Main(input){

input=parseInt(input);
answer = 100000;
a = input - 1;
b = 1

for (; a > 0; a--,b++) {
    sum = 0;
    aa = a.toString(10);
    ak = aa.length - 1;
    bb = b.toString(10);
    bk = bb.length - 1;
    for (; ak >= 0; ak--) {
        sum = sum + parseInt(aa[ak]);
    }
    for (; bk >= 0; bk--) {
        sum = sum + parseInt(bb[bk]);
    }
    if (sum < answer) {
        answer = sum;
    }
}

console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
