402203: GYM100694 M The Fifth Season

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

M. The Fifth Seasontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Cersei and Jaime has stolen n gold coins from the Casterly Rock reserves. They decided to play a game while the disappearence is not detected.

The game consists of q rounds. At the beginning of each round all n coins lie in a heap. The players move in rotation, taking from the heap no less than ki and no more than li coins (ki ≤ li, i is the number of round). The player who can't do the move loses.

Cersei and Jaime have determined the pairs of numbers (ki, li) for each round of the game. They don't see any point in finding out who wins in what round as they choose who moves the first by flipping a coin. They are interested in the maximal length of each round, provided that they play optimally (intend to win). The length of the round is the total number of moves made by both Cersei and Jaime.

Your task is to find the maximal possible length of each round of the game.

Input

The first line contains two integers n and q — the number of coins and the number of rounds (1 ≤ n ≤ 106, 1 ≤ q ≤ 105).

Each of the next q lines contains two integers ki and li  — the minimal and maximal number of coins that could be taken at one turn in the i-th round.

Output

Write q space-separated integers. The i-th number should be equal to the maximal possible length of the i-th round.

ExamplesInput
10 2
1 1
5 6
Output
10 1 

加入题单

上一题 下一题 算法标签: