Bookshelf Sorting

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Irma works in a library. Every day she watches visitors take a couple of books from the bookshelf, read them, and put books back in the same places they took them. Usually people mess up the order and swap two books they read. Let's take a look at one specific bookshelf with nn books in some order, numbered from 11 to nn from left to right. The ii-th visitor takes books from positions x_ix\_i and y_iy\_i and puts them back on the same positions, but in the wrong order. After the ii-th visitor, the book that was at x_ix\_i is now at position y_iy\_i and vice versa. 

In the evening, after the library is closed, Irma wants to put all the books back on their places. For each book there is a number p_ip\_i --- a position where that book should end up in the end. To rearrange books, Irma can take any book from the shelf and insert it in the beginning or in the end (so it ends up in the first or in the last place on the shelf).

What is the minimum number of moves Irma can do to put all books in order? Answer this question for some initial placement of books, determined by p_ip\_i, and after each visitor that swapped places of some two books.

입력

The first line contains two integers nn and qq (2n21052 \le n \le 2 \cdot 10^5; 0q21050 \le q \le 2 \cdot 10^5) --- the number of books on the shelf and the number of visitors. The next line contains nn distinct integers p_ip\_i (1p_in1 \le p\_i \le n), meaning that the book in the ii-th position must end up in position p_ip\_i.

Next qq lines describe library's visitors. Each line contains two integers x_ix\_i, y_iy\_i (1x_i<y_in1 \le x\_i < y\_i \le n), that mean that the ii-th visitor swapped two books on positions  x_ix\_i and y_iy\_i.

출력

Print q+1q + 1 integers --- the minimum number of moves required to sort all books for the initial order, then for the order the after the first visitor, \ldots, after all qq visitors.

힌트

The initial order of books is (5,1,2,4,3)(5, 1, 2, 4, 3). To sort these books out, first, put the book 44 in the end, then do the same with book 55. After the first visitor, the bookshelf now looks like (5,1,2,3,4)(5, 1, 2, 3, 4); it's enough to just move the book 55 to the end. After the second visitor the order of books is (3,1,2,5,4)(3, 1, 2, 5, 4). For this order the minimum number of moves is 33, there are several ways to achieve the final order in 33 moves.