//package Contest546;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class mainD {
    public static Scanner enter = new Scanner(System.in);
    public static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        int n=enter.nextInt();
        int m=enter.nextInt();
        ArrayList<Integer>[] mass =new ArrayList[n+1];
        ArrayList<Integer>[] they_me =new ArrayList[n+1];
        for (int i = 0; i <n+1 ; i++) {
            mass[i]=new ArrayList<>();
            they_me[i]=new ArrayList<>();
        }
        int[] arr=new int[n+1];
        int[] place=new int[n+1];
        for (int i = 1; i <n+1 ; i++) {
            arr[i]=enter.nextInt();
            place[arr[i]]=i;
        }

        for (int i = 1; i <=m ; i++) {
            int a=enter.nextInt();
            int b=enter.nextInt();
            mass[b].add(a);
            they_me[a].add(b);
        }
        int obj=arr[n];
        int[] friends = new int[mass[obj].size()];
        for (int i = 0; i <friends.length ; i++) {
            friends[i]=place[mass[obj].get(i)];
        }
        int ans=0;
        Arrays.sort(friends);

        /*System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(place));
        System.out.println(Arrays.toString(friends));*/
        for (int i = friends.length-1; i >=0 ; i--) {
            int tmp=arr[friends[i]];
            int s=n-friends[i]-1;
            for (int j = 0; j <they_me[tmp].size() ; j++) {
                if(they_me[tmp].get(j)==obj) continue;
                if(place[they_me[tmp].get(j)]>friends[i]) s--;
                if(s<=0) break;
            }
            if(s<=0) {
                if(i!=0){
                    they_me[arr[friends[i-1]]].add(tmp);
                }
                ans++;
            }
        }
        System.out.println(ans);
    }
}
