import java.util.*;
import java.io.*;




public class answer{
    
    
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int[] p = new int[n];
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){
            p[i] = Integer.parseInt(st.nextToken());
        }
        int u,v;
        HashSet<Integer>[] hs = new HashSet[n+1];
        
        boolean[] ok = new boolean[n+1];
        for(int i=0;i<m;i++){
            st = new StringTokenizer(br.readLine());
            u = Integer.parseInt(st.nextToken());
            v = Integer.parseInt(st.nextToken());
            if(!ok[v]) {
                ok[v] = true;
                hs[v] = new HashSet<Integer>();
            }
            
            hs[v].add(u);
            
        }
        
        HashSet<Integer> sd = hs[p[n-1]];
        int sum = 0;
        for(int i=n-2;i>=0;i--){
            //System.out.println(p[i]+" :");
            //for(int x:sd) System.out.print(x+" ");
            //System.out.println(" ");
            if(sd==null) break;
            if(sd.isEmpty()) break;
            if(sd.contains(p[i])){
                sum++;
                sd.remove(p[i]);
            }
            if(hs[p[i]]==null) break;
            sd.retainAll(hs[p[i]]);
        }
        System.out.println(sum);
    }
}