import java.util.*;

public class D546 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n, m;
        n = scanner.nextInt();
        m = scanner.nextInt();
        int[] queue = new int[n];
        int[][] rep = new int[n + 1][n + 1];
        HashMap<Integer, Set<Integer>> mp = new HashMap<>();
        for (int i = 0; i < n; i++){
            queue[i] = scanner.nextInt();
        }

        for (int i = 0 ; i < m; i++){
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            rep[u][v] = 1;
            Set<Integer> set = mp.getOrDefault(v, new HashSet<>());
            set.add(u);
            mp.put(v, set);
        }

        int cnt = 0;
        Set<Integer> allowed = new HashSet<>();
        boolean setAllowed = true;
        for (int i = n - 2; i >= 0; i--){
            if (rep[queue[i]][queue[n -1]] == 1){
                cnt++;
                allowed.clear();
                setAllowed = true;
                continue;
            }
            if (setAllowed){
                allowed = mp.getOrDefault(queue[i], new HashSet<>());
                setAllowed = false;
            }else {
                for (Integer integer : allowed) {
                    if (!mp.get(queue[i]).contains(integer)){
                        allowed.remove(integer);
                    }
                }
            }
        }
        System.out.println(cnt);
    }
}
