SP4390 CARDSHUF - Cards shuffing
Description
[English](/problems/CARDSHUF/en/) [Tiếng Việt](/problems/CARDSHUF/vn/)"Phú ông" has a card deck consits of n cards. He writes on each card a number from 1 to n from the top to the bottom of the deck.
Then he does shuffle the card deck several times, each time is described by **S(i, j)** meaning: pull out the i $ ^{th} $ card then put it on the j $ ^{th} $ of the remaining cards (1 For example (**n=6**):

Afer x times of shuffing, "Phú ông" gives "Bờm" the card deck and chanllenges him to make it into the original order. Please help "Bờm"!
Input Format
\- The first line contains two integer n, x.
\- Next x line(s), the p $ ^{th} $ line contains two integer i $ _{p} $ , j $ _{p} $ describing the p $ ^{th} $ time of shuffing (**S(i $ _{p} $ , j $ _{p} $ )**).
Output Format
\- A single integer means the minimal number of times of shuffing the card deck to help "Bờm".