import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class cf {
	public static void main(String[] args) {
		FS scan = new FS(System.in);
		int N = scan.nextInt(), M = scan.nextInt();
		
		int[] list = new int[N], rev = new int[N];
		for(int i=0;i<N;i++){
			list[i] = scan.nextInt()-1;
			rev[list[i]] = i;
		}
		
		ArrayList<Integer> jumpers = new ArrayList<>();
		ArrayDeque<Integer>[] adj = new ArrayDeque[N];
		for(int i=0;i<N;i++)adj[i] = new ArrayDeque<>();
		for(int i=0;i<M;i++){
			int u = scan.nextInt()-1, v = scan.nextInt()-1;
			adj[u].add(v);
			if(v==list[N-1])
				jumpers.add(u);
		}
		
		int[] countToRight = new int[N];
		boolean[] canJump = new boolean[N];
		for(int i : jumpers) {
			canJump[rev[i]] = true;
			for(int j : adj[i]){
				if(j==list[N-1])continue;
				if(rev[j] > rev[i]) countToRight[i]++;
			}
		}
		
		int sum = 0, sol = 0;
		for(int i=N-2;i>=0;i--){
			if(canJump[i]){
				if(sum==countToRight[list[i]]-sol)
					sol++;
			} else{
				sum++;
			}
		}
		System.out.println(sol);
	}
	
	private static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() { return Double.parseDouble(next());}
	}
}
