#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    int K;
    cin >> K;
    int d[K+1]; //modK = 0,1,2,....,K-1
    fill(d, d + K, 1e9); 
    d[1] = 1;
    deque<int> que;
    que.push_back(1);
    while(!que.empty()) {
        int p = que.front(); que.pop_front();
        if(d[(p+1)%K] > d[p] + 1) {
            d[(p+1)%K] = d[p] + 1; que.push_back((p+1)%K);
        }
        if(d[(p*10)%K] > d[p]) {
            d[(p*10)%K] = d[p]; que.push_front((p*10)%K);
        }
        /*
        for(int i = 0; i < K; ++i) {
            cout << d[i] << " ";
        }
        cout << endl;
        */
    }
    cout << d[0] << endl;
    return 0;
}