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

#GL0000134. Ước chung yếu (Weakened Common Divisor)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ước chung yếu (Weakened Common Divisor)

Weakened Common Divisor

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn pairs (ai,bi)(a_i,b_i), an integer d>1d>1 is called a weakened common divisor if, for every pair, dd divides at least one of aia_i or bib_i. Output any such divisor, or -1 if none exists. No optimization of dd is required.

Input

The first line contains nn, followed by nn lines each containing ai,bia_i,b_i.

Output

Print any valid integer d>1d>1, or -1 if none exists.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; 2≤ai,bi≤1 0002\le a_i,b_i\le 1\,000.
  • Subtask 2 (30 points): 1≤n≤1 0001\le n\le 1\,000; 2≤ai,bi≤1 000 0002\le a_i,b_i\le 1\,000\,000.
  • Subtask 3 (50 points): 1≤n≤150 0001\le n\le 150\,000; 2≤ai,bi≤2 000 000 0002\le a_i,b_i\le 2\,000\,000\,000.

Examples

Input

3
17 18
15 24
12 15

Output

2

Explanation

The value 2 divides 18 in pair 1, 24 in pair 2, and 12 in pair 3. Hence every pair contains an integer divisible by 2, so the output is valid.