import java.util.*;
import java.io.*;

public class D {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] q = new int[N];
        for(int i = 0; i < N; i++) q[i] = scanner.nextInt()-1;
        DSU dsu = new DSU(N);
        boolean[] can = new boolean[N];
        while(M-->0) {
            int u = scanner.nextInt()-1;
            int v = scanner.nextInt()-1;
            if (u == q[N-1] || v==q[N-1]) {
                can[u] = true;
                can[v] = true;
            }
            else dsu.union(u, v);
        }
        int p1 = N-2;
        int ans = 0;
        while(p1 >= 0) {
            //todo bounds checking
            ArrayList<Integer> list = new ArrayList<>();
            while(p1 > 0 &&  dsu.find(q[p1-1]) == dsu.find(q[p1])) {
                list.add(q[p1]);
                p1--;
            }
            list.add(q[p1--]);
            int temp = 0;
            for(int i : list) {
                if (can[i]) temp++;
            }
            ans += temp;
            if (temp < list.size()) break;
        }
        out.println(ans);
        out.flush();
    }
    
    public static class DSU {
        int[] parent, rank;
        int size, nSets;
        public DSU(int ss) {
            size =ss;
            nSets = ss;
            parent = new int[ss];
            rank = new int[ss];
            for(int i = 0; i < ss; i++) {
                parent[i] = i;
                rank[i] = 1;
            }
        }
        public int find(int t) {
            int prev = t;
            while(parent[t] != t) t =parent[t];
            compress(prev, t);
            return t;
        }
        public void compress(int s, int t) {
            while(parent[s] != t) {
                int temp = parent[s];
                parent[s] = t;
                s = temp;
            }
        }
        public boolean union(int a, int b) {
            int pa = find(a);
            int pb = find(b);
            if(pa == pb) return false;
            nSets--;
            if (rank[pa] <= rank[pb]) {
                rank[pb] += rank[pa];
                parent[pa] = pb;
            }
            else {
                rank[pa] += rank[pb];
                parent[pb] = pa;
            }
            return true;
        }
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}
