题目描述
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
You are given two integers $L$ and $R$. Find the smallest non-negative integer $N$ such that
$$N \,\%\, L > N \,\%\, (L + 1) > \ldots > N \,\%\, (R - 1) > N \,\%\, R \,.$$
Here, $\%$ is the modulo operator, so $A \,\%\, B$ is the remainder of $A$ after division by $B$. For example, $11 \,\%\, 3 = 2$.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $L$ and $R$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible $N$, or $-1$ if no solution exists.
It is guaranteed that when a solution exists, the smallest solution does not exceed $10^{18}$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ L < R ≤ 10^{6}$
----- Sample Input 1 ------
2
4 6
1 2
----- Sample Output 1 ------
6
-1
----- explanation 1 ------
Example case 1: $N = 6$ satisfies the given condition, since $6 \,\%\, 4 \,(= 2) > 6 \,\%\, 5 \,(= 1) > 6 \,\%\, 6 \,(= 0)$. Notice that $N = 7$ also satisfies the condition, but it is larger.
Example case 2: It is impossible to find a valid solution because for any non-negative integer $N$, we have $N \,\%\, 1 \,(= 0) ≤ N \,\%\, 2$.
输入格式
见题面
输出格式
见题面