#arc097b. [arc097_b]Equals
[arc097_b]Equals
Problem Statement
We have a permutation of the integers from through , , , .., . We also have pairs of two integers between and (inclusive), represented as , , .., . AtCoDeer the deer is going to perform the following operation on as many times as desired so that the number of ( ) such that is maximized:
- Choose such that , and swap and .
Find the maximum possible number of such that after operations.
Constraints
- is a permutation of integers from through .
- If , .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible number of such that 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 , becomes 1 3 5 4 2
, which is optimal, so the answer is .
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 , , in this order, becomes 1 2 3
, which is obviously optimal. Note that we may choose the same 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.