Choose k different positive integers a1, a2, …, ak. For some non-negative m, divide it by every ai (1 ≤ i ≤ k) to find the remainder ri. If a1, a2, …, ak are properly chosen, m can be determined, then the pairs (ai, ri) 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.
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.
2 8 7 11 9 4 18373 16147 8614 14948 8440 17480 22751 21618 6 19576 8109 18992 24177 9667 17726 16743 19533 16358 12524 8280 22731 4 9397 38490 22001 25094 33771 38852 19405 35943
31 13052907343337200 -1 78383942913636233