import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

alias Edge = Tuple!(int, "to", int, "cost");
alias Node = Tuple!(int, "num", int, "d");

void main() {
    int k;
    scan(k);

    auto adj = new Edge[][](k, 0);

    foreach (i ; 0 .. k) {
        adj[i] ~= Edge((i + 1) % k, 1);
        adj[i] ~= Edge((i * 10) % k, 0);
    }

    int ans = dijkstra(k, adj) + 1;

    writeln(ans);
}

int dijkstra(int k, Edge[][] adj) {
    auto minhp = new BinaryHeap!(Array!Node, "a.d > b.d")();
    auto d = new int[](k);
    d[] = 100;
    d[1] = 0;

    minhp.insert(Node(1, 0));

    while (!minhp.empty) {
        auto v = minhp.front;
        minhp.popFront();

        if (d[v.num] < v.d) continue;

        if (v.num == 0) return v.d;

        foreach (e ; adj[v.num]) {
            if (d[v.num] + e.cost < d[e.to]) {
                d[e.to] = d[v.num] + e.cost;
                minhp.insert(Node(e.to, d[e.to]));
            }
        }
    }

    assert(0);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}