from collections import Counter

n,m=map(int,input().split())
a=[int(x) for x in input().split()]

adj=[set() for i in range(n+1)]
xx=a[-1]
ind=Counter()
for i in range(n):
    ind[a[i]]=i

for i in range(m):
    u,v=map(int,input().split())
    if ind[v]>ind[u]:
        adj[v].add(u)
print(adj)
s=set()
an=0
vis=[0]*(n+1)
c=1
for j in adj[a[-1]]:

    vis[j]+=1
for i in range(n-2,-1,-1):

    if vis[a[i]]==c :

        an+=1
    else:
        for j in adj[a[i]]:
            vis[j] += 1
        c+=1
    # print(vis,c)
print(an)