import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		Reader in = new Reader();
		int n = in.nextInt();
		int m = in.nextInt();
		int[] a = in.na(n);
		/*
		int[] pos = new int[n+1];
		for(int i = 0; i<n; i++) pos[a[i]] = i+1;
		*/
		ArrayList<Integer>[] adj = new ArrayList[n+1];
		for(int i = 0; i<n+1; i++) adj[i] = new ArrayList<Integer>();
		for(int i = 0; i<m; i++) adj[in.nextInt()].add(in.nextInt());
		int pos = n-1;
		ArrayList<Integer> pass = new ArrayList<Integer>();
		pass.add(a[n-1]);
		int ans = 0;
		for(int i = n-2; i>=0; i--){
		    int cur = a[i];
		    boolean passAll = true;
		    for(int j = 0; j<pass.size()&&passAll; j++){
		        if(!adj[cur].contains(pass.get(j))) passAll = false;
		    }
		    if(passAll){
		        		   // System.out.println("Passed: "+cur+"");
		        ans++;
		    }else{
		        pass.add(cur);
		    }
		        
		}
		System.out.println(ans);
	}
	static class Reader {
		static BufferedReader br;
		static StringTokenizer st;
		public Reader() {
			this.br = new BufferedReader(new InputStreamReader(System.in));
		}
		public int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public int nextInt() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Integer.parseInt(st.nextToken());
		}
		public double nextDouble() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Double.parseDouble(st.nextToken());
		}
		public Long nextLong() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Long.parseLong(st.nextToken());
		}
		public String next() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return st.nextToken();
		}
		private static void readLine() {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
			}
		}
	}
}