// i will show you da wae
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fill(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 100020
using namespace std;
typedef long long ll;
typedef pair<ll,int> ii;
typedef long double ld;

int getSum(ll x){
	int ans = 0;
	while(x > 0) ans += x%10, x /= 10;
	return ans;
}

int main(){
	
	ll n;
	cin >> n;
	int best = getSum(n);
	ll cur = n;
	FOR(i,1,10000000){
		cur += n;
		best = min(best,getSum(cur));
	}
	
	cout << best << endl;
	
	return 0;
}