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

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        HashSet<Integer>[] adj = new HashSet[n+1];
        HashSet<Integer> set = new HashSet<>();
        for (int i = 1; i <= n; i++) set.add(n);

        for (int i = 0; i <= n; i++) adj[i] = new HashSet<>();
        int[] a = new int[n];
        st = new StringTokenizer(in.readLine());
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }
        for (int i = 0; i < m; i++) {
            st = new StringTokenizer(in.readLine());
            int u = Integer.parseInt(st.nextToken());
            int v = Integer.parseInt(st.nextToken());
            adj[u].add(v);
        }
        int res = 0;
        for (int i = n-2; i >= 0; i--) {
            for (int j : set) {
                if (!adj[j].contains(a[i]) && j != a[i]) {
                    set.remove(j);
                }
            }
            if (adj[a[i]].contains(a[n-1])) {
                res++;
            }
        }
        out.println(res);
        out.close();
    }

}
/*

 */