import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*


fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val k = sc.nextInt()

    val vs = Array(k) { Vertex(it) }

    for (x in 1 until k) {
        vs[x].adj.add(Edge(vs[(x * 10) % k], 0))
        vs[x].adj.add(Edge(vs[(x + 1) % k], 1))
    }

    vs[1].dist = 0

    val bfs = PriorityQueue<Vertex>()
    var count = 0

    bfs.add(vs[1])
    while (!bfs.isEmpty()) {
        val v = bfs.poll()
        //if (v.solved) continue


        v.solved = true
        for (edge in v.adj) {
            count += 1
            if (edge.to.dist == -1 || edge.to.dist > v.dist + edge.length) {
                edge.to.dist = v.dist + edge.length
                bfs.add(edge.to)
            }
        }
    }

    println(vs[0].dist + 1)

}


data class Vertex(val x: Int): Comparable<Vertex> {
    override fun compareTo(other: Vertex): Int {
        return this.dist - other.dist
    }

    var dist = -1
    var solved = false
    val adj = mutableListOf<Edge>()
}

class Edge(val to: Vertex, val length: Int)


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


