Hanafuda Shuffle

No attempts yetTime limit1sMemory limit128 MB

Problem

There are many ways to shuffle a deck of cards. The Hanafuda shuffle, used for the Japanese card game Hanafuda, is one of them. It works as follows.

You have a deck of $n$ cards. In one cutting operation, you take the $c$ cards that begin at the $p$-th card from the top, pull that contiguous block out of the deck, and place it on top of the deck, keeping the block's internal order unchanged. A shuffle applies a sequence of such cutting operations, one after another.

Write a program that simulates a Hanafuda shuffle and reports which card ends up on top of the deck.

Input

The input consists of several data sets. Each data set begins with a line containing two positive integers $n$ and $r$ ($1 \le n \le 50$, $1 \le r \le 50$): the number of cards in the deck and the number of cutting operations, respectively.

The next $r$ lines each describe one cutting operation, and the operations are performed in the given order. Each such line contains two positive integers $p$ and $c$ with $p + c \le n + 1$: starting from the $p$-th card from the top, $c$ cards are pulled out and placed on top.

The end of the input is a line containing two zeros. Every input line contains exactly two integers separated by a single space, with no other characters.

Output

For each data set, print the number of the top card after the shuffle on its own line. At the start, the cards are numbered $1$ to $n$ from the bottom of the deck to the top. Do not print any extra characters such as leading or trailing spaces.