import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Iterator;

public class Solve4 {

    public static void main(String[] args) throws IOException {
        PrintWriter pw = new PrintWriter(System.out);
        new Solve4().solve(pw);
        pw.flush();
        pw.close();
    }

    public void solve(PrintWriter pw) throws FileNotFoundException, IOException {
        FastReader sc = new FastReader();
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n + 1];
        int[] index = new int[n + 1];
        int[] cnt = new int[n + 1];
        HashSet<Integer>[] al = new HashSet[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            index[a[i]] = i;
            cnt[a[i]] = n - i;
            al[i] = new HashSet();
        }
        cnt[a[n]] = -1;
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt(), y = sc.nextInt();
            al[x].add(y);
        }
        SegmentTree st = new SegmentTree(a);
        for (int i = n - 1, s = 0; i > 0; i--) {
            int x = a[i];
            Iterator<Integer> it = al[x].iterator();
            cnt[x] -= s;
            while (it.hasNext()) {
                int y = it.next();
                if(cnt[y]!=0){
                    if (st.query(1, 1, n, index[x] + 1, n, y)) {
                        cnt[x]--;
                        if (cnt[x] == 0) {
                            s++;
                        }
                    }
                }
            }
        }
        int ans = 0;
        for (int i = n - 1; i >= 1; i--) {
            if (cnt[i] <= 0) {
                ans++;
            }
        }
        pw.println(ans);
    }

    static class SegmentTree {

        int[] st, a;

        public SegmentTree(int[] a) {
            this.a = a;
            st = new int[a.length << 2];
            build(1, 1, a.length - 1);
        }

        public void build(int nd, int l, int r) {
            if (l == r) {
                st[nd] = a[l];
                return;
            }
            int mid = (l + r) / 2;
            build(nd << 1, l, mid);
            build(nd << 1 | 1, mid + 1, r);
        }

        public boolean query(int nd, int l, int r, int from, int to, int val) {
            if (from > r || to < l) {
                return false;
            }
            if (l == r) {
                if (st[nd] == val) {
                    return true;
                }
                return false;
            }
            int mid = (l + r) / 2;
            boolean f1 = query(nd << 1, l, mid, from, to, val);
            boolean f2 = query(nd << 1 | 1, mid + 1, r, from, to, val);
            return f1 || f2;
        }
    }

    static public class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(System.in));

        }

        public String next() throws IOException {
            if (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }
    }
}
