Create a program to find the smallest natural number that is a member of all given infinite arithmetic progressions of natural numbers.
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 the smallest number that belongs to all progressions. If no such number exists, output 0.
Example 1