{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n \u003cp\u003e\u003c/p\u003eElina正在读一本由刘若嘉撰写的书,它介绍了一种表达非负整数的奇怪方法。方法描述如下:选择k个不同的正整数a1,a2,...,ak。对于一些非负m,将其除以ai(1≤i≤k)以找到余数ri。如果正确选择a1,a2,...,ak,则可以确定m,然后可以使用对(ai,ri)来表示m。 “很容易计算出m,”Elina说。 “但我怎样才能找到m?”因为Elina是编程新手,所以这个问题对她来说太难了。你能救她吗?\u003c/p\u003e\n \u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n \u003cp\u003eThe input contains multiple test cases. Each test cases consists of some lines.\u003c/p\u003e\n \u003cul\u003e\n \u003cli\u003eLine 1: Contains the integer \u003ci\u003ek\u003c/i\u003e.\u003c/li\u003e\n \u003cli\u003eLines 2 ~ \u003ci\u003ek\u003c/i\u003e + 1: Each contains a pair of integers \u003ci\u003ea\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e, \u003ci\u003er\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e (1 ≤ \u003ci\u003ei\u003c/i\u003e ≤ \u003ci\u003ek\u003c/i\u003e).\u003c/li\u003e\n \u003c/ul\u003e\n \u003cp\u003e\u003c/p\u003e\n \u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n \u003cp\u003eOutput the non-negative integer \u003ci\u003em\u003c/i\u003e 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 \u003ctt\u003e-1\u003c/tt\u003e.\u003c/p\u003e\n \u003cp\u003e\u003c/p\u003e\n \u003c/div\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e2\n8 7\n11 9\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e31\u003c/pre\u003e"}},{"title":"Hint","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n \u003cp\u003eAll integers in the input and the output are non-negative and can be represented by 64-bit integral types.\u003c/p\u003e\n \u003c/div\u003e"}}]}