import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;

public class Codeforces {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = in.nextInt();
        int m = in.nextInt();

        int[] q = new int[n];
        int[] index = new int[n + 1];
        Map<Integer, Set<Integer>> canSwap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            q[i] = in.nextInt();
            index[q[i]] = i;

            canSwap.put(q[i], new HashSet<>());
        }


        for (int i = 0; i < m; i++) {
            int f = in.nextInt();
            int s = in.nextInt();

            if (index[f] < index[s]) {
                canSwap.get(f).add(s);
            }
        }

        int res = 0;
        int tar = q[q.length - 1];
        Set<Integer> used = new HashSet<>();
        int countToSwap = 0;
        for (int i = q.length - 2; i >= 0; i--) {
            int cur = q[i];

            if (canSwap.get(cur).contains(tar)) {
                int size = canSwap.get(cur).size();
                if (canSwap.get(cur).size() > used.size()) {
                    for (int useP : used) {
                        if (canSwap.containsKey(useP)) {
                            size--;
                        }
                    }
                } else {
                    for (int curP : canSwap.get(cur)) {
                        if (used.contains(curP)) {
                            size--;
                        }
                    }
                }

                if (countToSwap == size - 1) {
                    used.add(cur);
                    res++;
                } else {
                    countToSwap++;
                }
            } else {
                countToSwap++;
            }
        }

        out.println(res);
        out.close();
    }

    public static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return null;
        }

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

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

        public int[] nextIntArr(int n) {
            int[] arr = new int[n];
            for (int j = 0; j < arr.length; j++) {
                arr[j] = nextInt();
            }

            return arr;
        }

        public long[] nextLongArr(int n) {
            long[] arr = new long[n];
            for (int j = 0; j < arr.length; j++) {
                arr[j] = nextLong();
            }

            return arr;
        }
    }
}