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

#GL0000308. Chuỗi số 7 (Repsept)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chuỗi số 7 (Repsept)

Repsept

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Consider the sequence 7,77,777,7777,…7,77,777,7777,\ldots. Its ii-th term is the decimal integer consisting of exactly ii digits, all equal to 77.

Given a positive integer KK, find the smallest index i≥1i\ge1 at which a term of this sequence is divisible by KK. If no term is divisible by KK, print -1.

Indices start at 11. A term can have hundreds of thousands of decimal digits, even though it cannot be represented by an ordinary integer type.

Input

One line contains the integer KK.

Output

Print the smallest 1-based index of a term divisible by KK; if none exists, print -1.

Subtasks

  • Subtask 1 (20 points): 1≤K≤1031\le K\le10^3, 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≤1061\le K\le10^6, KK is an integer.

Examples

Example 1

Input

101

Output

4

Explanation

The remainders of 77, 7777, 777777 modulo 101101 are 7,77,707,77,70. Since 7777=101⋅777777=101\cdot77, the first divisible term occurs at index 44.

Example 2

Input

2

Output

-1

Explanation

Every term ends in digit 77, so each is odd and none can be divisible by 22.

Example 3

Input

999983

Output

999982

Explanation

The term consisting of 999982999982 digits 77 is divisible by 999983999983, and none of the shorter terms is divisible. Thus the answer is 999982999982.