//package CodeForces_practice;

import java.util.Arrays;
import java.util.Scanner;

public class D1136 {
static	boolean [][] swp;
static int [] pos;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int m=s.nextInt();
		 swp=new boolean[n+1][n+1];
		 pos=new int [n+1];
		for(int i=1;i<n+1;i++)
		{
			pos[i]=s.nextInt();
		}
		for(int i=0;i<m;i++)
		{
			swp[s.nextInt()][s.nextInt()]=true;
		}
		System.out.println(pushForward(n));
		
		
	}
	public static int pushForward(int indx)
	{
		
		int count=0;
		while(swp[pos[indx-1]][pos[indx]])
		{
			indx--;
			int temp=pos[indx+1];
			pos[indx+1]=pos[indx];
			pos[indx]=temp;
			count++;
		}
		//System.out.println(Arrays.toString(pos));
		int posF=1;
		for(int i=indx-1;i>posF;i--)
		{
			if(!swp[pos[i]][pos[indx]])
			{
				posF=i-pushForward(i);
			}
		}
		while(swp[pos[indx-1]][pos[indx]])
		{
			indx--;
			int temp=pos[indx+1];
			pos[indx+1]=pos[indx];
			pos[indx]=temp;
			count++;
		}
		return count;
		
		
	}

}
