Strange Way to Express Integers
题号:NC51047
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is described as following:
Choose k different positive integers . For some non-negative m, divide it by every to find the remainder ri. If are properly chosen, m can be determined, then the pairs (a_i, r_i)can be used to express m.
“It is easy to calculate the pairs from m, ” said Elina. “But how can I find m from the pairs?”
Since Elina is new to programming, this problem is too difficult for her. Can you help her?

输入描述:

The input contains multiple test cases. Each test cases consists of some lines.
Line 1: Contains the integer k.
Lines 2 ~ k + 1: Each contains a pair of integers

输出描述:

Output the non-negative integer m on a separate line for each test case. If there are multiple possible values, output the smallest one. If there are no possible values, output -1.
示例1

输入

复制
2
8 7
11 9

输出

复制
31

说明

All integers in the input and the output are non-negative and can be represented by 64-bit integral types.