Common Element#7214

Common Element

1 second
64 megabytes
Easy

Create a program to find the smallest natural number that is a member of all given infinite arithmetic progressions of natural numbers.

Input

The input consists of (2n + 1) non-negative integers. The first integer is , where n < 100. For each -th pair of numbers following , the first number represents the first term of the -th progression, and the second number is the common difference. All numbers are no greater than .

Output

Output the smallest number that belongs to all progressions. If no such number exists, output 0.

Examples

Example 1

Loading
Loading