You have a set of n discs, the i-th disc has radius i. Initially, these discs are split among m towers: each tower contains at least one disc, and the discs in each tower are sorted in descending order of their radii from bottom to top.

You would like to assemble one tower containing all of those discs. To do so, you may choose two different towers i and j (each containing at least one disc), take several (possibly all) top discs from the tower i and put them on top of the tower j in the same order, as long as the top disc of tower j is bigger than each of the discs you move. You may perform this operation any number of times.

For example, if you have two towers containing discs [6, 4, 2, 1] and [8, 7, 5, 3] (in order from bottom to top), there are only two possible operations:

  * move disc 1 from the first tower to the second tower, so the towers are [6, 4, 2] and [8, 7, 5, 3, 1]; 
  * move discs [2, 1] from the first tower to the second tower, so the towers are [6, 4] and [8, 7, 5, 3, 2, 1]. 



Let the difficulty of some set of towers be the minimum number of operations required to assemble one tower containing all of the discs. For example, the difficulty of the set of towers [[3, 1], [2]] is 2: you may move the disc 1 to the second tower, and then move both discs from the second tower to the first tower.

You are given m - 1 queries. Each query is denoted by two numbers a_i and b_i, and means "merge the towers a_i and b_i" (that is, take all discs from these two towers and assemble a new tower containing all of them in descending order of their radii from top to bottom). The resulting tower gets index a_i.

For each k ∈ [0, m - 1], calculate the difficulty of the set of towers after the first k queries are performed.

Input

The first line of the input contains two integers n and m (2 ≤ m ≤ n ≤ 2 ⋅ 10^5) — the number of discs and the number of towers, respectively.

The second line contains n integers t_1, t_2, ..., t_n (1 ≤ t_i ≤ m), where t_i is the index of the tower disc i belongs to. Each value from 1 to m appears in this sequence at least once.

Then m - 1 lines follow, denoting the queries. Each query is represented by two integers a_i and b_i (1 ≤ a_i, b_i ≤ m, a_i ≠ b_i), meaning that, during the i-th query, the towers with indices a_i and b_i are merged (a_i and b_i are chosen in such a way that these towers exist before the i-th query).

Output

Print m integers. The k-th integer (0-indexed) should be equal to the difficulty of the set of towers after the first k queries are performed.

Example

Input


7 4
1 2 3 3 1 4 3
3 1
2 3
2 4


Output


5
4
2
0

Note

The towers in the example are:

  * before the queries: [[5, 1], [2], [7, 4, 3], [6]]; 
  * after the first query: [[2], [7, 5, 4, 3, 1], [6]]; 
  * after the second query: [[7, 5, 4, 3, 2, 1], [6]]; 
  * after the third query, there is only one tower: [7, 6, 5, 4, 3, 2, 1]. 
import java.util.*;
import java.io.*;

public class Solution {


    public Solution(FastScanner in, PrintWriter out) {

        N = in.nextInt();
        M = in.nextInt();

        root = new int[M];
        towers = new ArrayList<>(M);
        for (int i = 0; i < M; i++) {
            towers.add(new ArrayList<>());
            root[i] = i;
        }

        A = new int[N]; // A[i] is the tower of ith disc

        int ans = N - 1; // at most n operations
        for (int i = 0; i < N; i++) {
            int t = in.nextInt() - 1;
            A[i] = t;
            towers.get(t).add(i);

            // if i and i-1 discs are on the same tower, one less operation
            if (i > 0 && A[i] == A[i - 1])
                ans--;
        }

        out.println(ans);

        for (int i = 0; i < M - 1; i++) {
            int v = find(in.nextInt() - 1);
            int u = find(in.nextInt() - 1);

            // merge smaller set into larger ones
            // there is no need to merge v into u
            // if we merge u into v and  an later queries have u,
            // find(u) returns v and thus we know 
            if (towers.get(v).size() < towers.get(u).size()) {
                int tmp = u;
                u = v;
                v = tmp;
            }

            for (int x : towers.get(u)) {
                if (x > 0 && A[x - 1] == v) ans--;
                if (x < N - 1 && A[x + 1] == v) ans--;
            }

            for (int x : towers.get(u)) {
                towers.get(v).add(x);
                A[x] = v;
            }

            towers.get(u).clear();

            root[u] = v;

            out.println(ans);
        }
    }

    private int N, M;
    private int[] A;
    private int[] root;
    private List<List<Integer>> towers;

    private int find(int u) {
        if (u != root[u])
            root[u] = find(root[u]);
        return root[u];
    }


    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        // int T = in.nextInt();
        int T = 1;

        for (int t = 0; t < T; t++) {

            Solution sol = new Solution(in, out);


            // String out = String.format("%s", ret);
            // System.out.println(out);
        }
        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream)
    {
        this.stream = stream;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}
