#include<cstdio>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize(3)
using namespace std;
const int maxn = 1e5 + 100;
typedef long long ll;

int cnt[maxn];
int sum[maxn];
inline int lowbit(int x) {return -x & x;}
void update(int a, int val) {
    while (a < maxn) {
        sum[a] +=val;
        a += lowbit(a);
    }
}
int cal(int a) {
    int ans = 0;
    while (a) {
        ans += sum[a];
        a -= lowbit(a);
    }
    return ans;
}
ll cl(ll a) {
    ll ans = 0;
    while (a) ans+=a%10, a/=10;
    return ans;
}
int main(){
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif // LOCAL
    ll a; scanf("%lld", &a);
    ll ans = 1e6, t = a+a;
    for (int i = 1; i < 1e6; i++) {
        ans = min(ans, cl(t));
        t+=a;
    }
    printf("%lld", ans);

    return 0;
}
