D - Small Multiple Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 700

問題文

K の正の倍数の 10 進法での各桁の和としてありうる最小の値を求めてください。

制約

  • 2 \leq K \leq 10^5
  • K は整数である

入力

入力は以下の形式で標準入力から与えられる。

K

出力

K の倍数の 10 進法での各桁の和としてありうる最小の値を出力せよ。


入力例 1

6

出力例 1

3

12=6×2 が最小値を達成します。


入力例 2

41

出力例 2

5

11111=41×271 が最小値を達成します。


入力例 3

79992

出力例 3

36

Score : 700 points

Problem Statement

Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

Constraints

  • 2 \leq K \leq 10^5
  • K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K.


Sample Input 1

6

Sample Output 1

3

12=6×2 yields the smallest sum.


Sample Input 2

41

Sample Output 2

5

11111=41×271 yields the smallest sum.


Sample Input 3

79992

Sample Output 3

36