import java.io.*;
import java.util.*;
 
public class swag {

	public static void main(String[] args)throws IOException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
		int n = in.nextInt();
		int m = in.nextInt();
		int arr[] = new int[n];
		HashSet[] sets = new HashSet[n];
		for(int t = 0; t < n; t++)
		{
			sets[t]=new HashSet<Integer>();
			arr[t]=in.nextInt()-1;
		}
		for(int i=0;i<m;i++)
		{
			int u = in.nextInt()-1;
			int v = in.nextInt()-1;
			sets[v].add(u);
		}
		HashSet lastSet = sets[arr[n-1]];
		// out.println("lastSet "+lastSet);
		HashSet cur = new HashSet<Integer>();
		cur.add(arr[0]);
		int ans[] = new int[n];
		Arrays.fill(ans,0);
		HashSet done = new HashSet<Integer>();
		for(int i=0;i<n-1;i++)
		{
			cur.retainAll(sets[arr[i]]);
			cur.add(arr[i]);
			cur.retainAll(lastSet);
			ans[i] = cur.size();
			if((i-1)>=0)
			{
				if(cur.contains(arr[i]))
					ans[i-1]-=(ans[i]-1);
				else
					ans[i-1]-=ans[i];
			}
		}
		int val = 0;
		// for(int i=0;i<n;i++)
		// {
		// 	out.println("i="+i+" "+ans[i]);
		// }
		for(int i=n-2;i>=0;i--)
		{
			if(ans[i]>0)
			{
				ans[i]--;
				if((i-1)>=0)
					ans[i-1]+=ans[i];
			}
			else
				break;
			val++;
		}
		out.println(val);
        out.close();
	}
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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 int nextInt() {
            return Integer.parseInt(next());
        }

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

    }

}