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

#GL0000235. Đội thi bao phủ mọi chủ đề (Quiz Master)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đội thi bao phủ mọi chủ đề (Quiz Master)

Đội thi bao phủ mọi chủ đề (Quiz Master)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given student skill values aia_i and topics 1..m1..m, student ii covers topic dd exactly when dd divides aia_i. Choose a nonempty group covering every topic, minimizing maximum skill minus minimum skill; print -1 if impossible.

Input

  • First line: n,mn,m.
  • Second line: nn integers aia_i.

Output

Print the minimum possible difference, or -1 if no team exists.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤20, 1≤ai≤1001\le n,m\le20,\ 1\le a_i\le100.
  • Subtask 2 (30 points): 1≤n,m≤3000, 1≤ai≤1041\le n,m\le3000,\ 1\le a_i\le10^4.
  • Subtask 3 (50 points): 1≤n,m≤105, 1≤ai≤1051\le n,m\le10^5,\ 1\le a_i\le10^5.

Examples

Example 1

Input

2 4
3 7

Output

-1

Explanation

Neither student covers topic 2 or 4, so the answer is -1.

Example 2

Input

4 2
3 7 2 9

Output

0

Explanation

The student with skill 2 covers both topics on their own, so the minimum difference is zero.