import sys
from collections import defaultdict
def move(arr,l,num,i):
    for j in range(i,n-1):
        if arr[j+1] in l:
            arr[j+1],arr[j]=arr[j],arr[j+1]
        else:
            return 
n,m=map(int,sys.stdin.readline().split())
arr=list(map(int,sys.stdin.readline().split()))
graph1=defaultdict(set)
for i in range(m):
    u,v=map(int,sys.stdin.readline().split())
    graph1[u].add(v)
num=arr[n-1]
for i in range(n-1,-1,-1):
    move(arr,graph1[arr[i]],arr[i],i)
for i in range(n):
    if arr[i]==num:
        break
print(n-1-i)
