There are cards numbered from to . When implementing your solution in C++, add the directive #define lll long long and use lll for 64-bit integers. When implementing your solution in Python, add the line lll = int at the beginning of the program and convert every value you read to a number with the call lll(...). Initially, each card was either empty or contained one positive integer. The same number could appear on several cards. The initial contents of the cards are unknown.
The cards underwent copy operations. In an operation , the contents of card were replaced with the contents of card . The contents of card did not change. If card was empty, card also became empty.
You are given all operations in the order in which they were performed. You also know that after all operations, card contains the number a_i. Thus, all cards are non-empty at the end.
Find the minimum possible number of cards that initially contained numbers. If the given final contents are impossible, report this.
Example for n = 3 and m = 2
The first line contains two integers and (1 \le n \le 2 \cdot 10^5, 0 \le m \le 2 \cdot 10^5) — the number of cards and the number of operations, respectively.
The second line contains integers a_1, a_2, \ldots, a_n (1 \le a_i \le 10^9) — the numbers on the cards after all operations.
Each of the next lines contains two integers and (1 \le x, y \le n, x \ne y), describing a copy from card to card . The operations are given in the order in which they were performed.
Print one integer — the minimum possible number of initially non-empty cards. If the given final contents are impossible, print .
Example 1
Example 2
Example 3
The first example is shown in the picture above. Card could initially contain the number , card could be empty, and card could contain the number . After the first operation, the numbers on the cards are ; after the second, they are . Fewer than two initially non-empty cards cannot suffice because copying does not create new numbers.
In the second example, after copying card to card , both cards must have the same contents. Therefore, the numbers and are impossible.
In the third example, it is enough to write the number only on card initially and leave the other cards empty. After three operations, all cards contain the number .