package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

type edge struct {
	from, to, cost int
}

func (e edge) LessThan(f edge) bool {
	return e.cost < f.cost
}

type priorityQueue []edge

func newPriorityQueue() priorityQueue {
	var a []edge
	a = append(a, edge{})
	return a
}

func (pq priorityQueue) Len() int {
	return len(pq) - 1
}

func (pq *priorityQueue) Push(e edge) {
	a := *pq
	n := len(a)
	a = append(a, e)

	for i, p := n, a.parent(n); p > 0 && a[i].LessThan(a[p]); i, p = p, a.parent(p) {
		a[i], a[p] = a[p], a[i]
	}
	*pq = a
}

func (pq *priorityQueue) Pop() edge {
	a := *pq
	res := a[1]
	n := len(a) - 1
	a[1] = a[n]
	a = a[:n]
	i := 1
	for {
		l := a.left(i)
		r := a.right(i)
		if n <= l {
			break
		}
		if n <= r {
			if a[l].cost < a[i].cost {
				a[i], a[l] = a[l], a[i]
			}
			break
		}
		if a[l].cost < a[r].cost {
			a[i], a[l] = a[l], a[i]
			i = l
		} else {
			a[i], a[r] = a[r], a[i]
			i = r
		}
	}
	*pq = a
	return res
}

func (pq priorityQueue) parent(i int) int {
	return i / 2
}

func (pq priorityQueue) left(i int) int {
	return i * 2
}
func (pq priorityQueue) right(i int) int {
	return i*2 + 1
}

func main() {
	defer stdout.Flush()

	k := readInt()

	g := make([][]edge, k)
	for i := range g {
		g[i] = make([]edge, 2)
		g[i][0] = edge{i, (i + 1) % k, 1}
		g[i][1] = edge{i, (i * 10) % k, 0}
	}

	pq := newPriorityQueue()
	push := func(e edge) {
		pq.Push(e)
	}
	pop := func() edge {
		return pq.Pop()
	}

	ans := make([]int, k)
	for i := range ans {
		ans[i] = math.MaxInt32
	}
	ans[1] = 0
	for _, es := range g[1] {
		push(es)
	}

	for pq.Len() != 0 {
		e := pop()
		if ans[e.to] <= ans[e.from]+e.cost {
			continue
		}
		ans[e.to] = ans[e.from] + e.cost
		for _, es := range g[e.to] {
			push(es)
		}
	}

	println(ans[0] + 1)

}


Measured memory_bytes: 23552