First day of school!
$n$ primary school freshmen are queuing up and each of them owns a student number. Teacher Mr. Cycle finds that the queue is unordered. In order to make the queue more orderly, he has to choose some pairs of students and exchange their positions.
However, Mr. Cycle is a lazy dog and impatient with making plans, so he asks for Miss. Ke's help. Specifically, Miss Ke gives Mr. Cycle a plan list of $m$ position pairs, and each pair $(p_1, p_2)$ means that Mr. Cycle can exchange the student at position $p_1$ and the student at position $p_2$ in the current queue (positions of the queue are numbered from $1$). Mr. Cycle trusts Miss Ke a lot, so he exchanges one by one strictly in the order of the plan list, and writes down the queuing chaotic value $V_i$ after $i$-th exchange for every $1 \le i \le m$.
Now Mr. Cycle wants to know the minimal queuing chaotic value $V = \min_{1\le i \le m}\{V_i\}$ in advance, so that he can stop exchanging at a proper time.
If we denote the student number of the student at position $i$ as $s_i$, the queuing chaotic value of a certain student queue equals the number of inversions, that is, the number of pairs $(i, j)$ such that $1 \le i < j \le n$ and $s_i > s_j$.