PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000310. Dãy số 2 (222)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy số 2 (222)

222

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Consider the sequence 2,22,222,2222,…2,22,222,2222,\ldots. The ii-th term is the positive decimal integer made of exactly ii digits, each of them equal to 22.

Given a positive integer KK, find the smallest index i≥1i\ge1 for which the ii-th term is divisible by KK. If no such term exists, print -1.

You must output the index, not the potentially enormous integer consisting of repeated digit 22.

Input

One line containing the positive integer KK.

Output

Print the smallest positive index of a term divisible by KK, or -1 if no such term exists.

Subtasks

  • Subtask 1 (20 points): 1≤K≤1001\le K\le100, KK is an integer.
  • Subtask 2 (30 points): 1≤K≤1051\le K\le10^5, KK is an integer.
  • Subtask 3 (50 points): 1≤K≤1081\le K\le10^8, KK is an integer.

Examples

Example 1

Input

1

Output

1

Explanation

The first term is 22, which is divisible by 11, hence the answer is 11.

Example 2

Input

7

Output

6

Explanation

The first six terms have remainders 2,1,5,3,4,02,1,5,3,4,0 modulo 77. The first zero remainder occurs at index 66.

Example 3

Input

10

Output

-1

Explanation

Every term ends in digit 22, so none is divisible by 1010, which would require the last digit to be 00.

Example 4

Input

999983

Output

999982

Explanation

The first term divisible by 999983999983 has 999982999982 digits equal to 22; all shorter positive lengths produce nonzero remainders.