#arc097b. [arc097_b]Equals

[arc097_b]Equals

Problem Statement

We have a permutation of the integers from 11 through NN, p1p_1, p2p_2, .., pNp_N. We also have MM pairs of two integers between 11 and NN (inclusive), represented as (x1,y1)(x_1,y_1), (x2,y2)(x_2,y_2), .., (xM,yM)(x_M,y_M). AtCoDeer the deer is going to perform the following operation on pp as many times as desired so that the number of ii (11 ii NN) such that pi=ip_i = i is maximized:

  • Choose jj such that 11 jj MM, and swap pxjp_{x_j} and pyjp_{y_j}.

Find the maximum possible number of ii such that pi=ip_i = i after operations.

Constraints

  • 22 NN 10510^5
  • 11 MM 10510^5
  • pp is a permutation of integers from 11 through NN.
  • 11 xj,yjx_j,y_j NN
  • xjx_j yjy_j
  • If ii jj, xi,yi\\{x_i,y_i\\} xj,yj\\{x_j,y_j\\}.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM p1p_1 p2p_2 .... pNp_N x1x_1 y1y_1 x2x_2 y2y_2 :: xMx_M yMy_M

Output

Print the maximum possible number of ii such that pi=ip_i = i after operations.


Sample Input 1

5 2
5 3 1 4 2
1 3
5 4

Sample Output 1

2

If we perform the operation by choosing j=1j=1, pp becomes 1 3 5 4 2, which is optimal, so the answer is 22.


Sample Input 2

3 2
3 2 1
1 2
2 3

Sample Output 2

3

If we perform the operation by, for example, choosing j=1j=1, j=2j=2, j=1j=1 in this order, pp becomes 1 2 3, which is obviously optimal. Note that we may choose the same jj any number of times.


Sample Input 3

10 8
5 3 6 8 7 10 9 1 2 4
3 1
4 1
5 9
2 5
6 5
3 5
8 9
7 9

Sample Output 3

8

Sample Input 4

5 1
1 2 3 4 5
1 5

Sample Output 4

5

We do not have to perform the operation.