#include <bits/stdc++.h>

#define pb push_back
#define y23oijdwnskd

using namespace std;

const int N = int(1e6 + 5);
const int INF = 1e9 + 7;

typedef long long ll;

int n;
int main (){
  scanf ("%d", &n);
  int l = 1, r = n, ans = INF;
  while (l <= r){
    int mid = l + r >> 1;
    int l2 = 1, r2 = n, f = 0;
    while (l2 <= r2){
      int mid2 = l2 + r2 >> 1;
      if (mid + mid2 > n){
        r2 = mid2 - 1;
      }
      else if (mid + mid2 < n){
        l2 = mid2 + 1;
      }
      else if (mid + mid2 == n){
        int a = mid, b = mid2, sum = 0;
        while (a){
          sum += (a % 10);
          a /= 10;
        }
        while (b){
          sum += (b % 10);
          b /= 10;
        }
        ans = min(ans, sum);
        f = 1;
        break;
      }
    }
    l = mid + 1;
  }
  cout << ans;
  return 0;
}
