from sys import stdin
n,m=map(int,stdin.readline().strip().split())
s=list(map(int,stdin.readline().strip().split()))
nas=s[-1]
g=set()
st=set()
for i in range(m):
    a,b=map(int,stdin.readline().strip().split())
    if b==nas:
        g.add(a)
    else:
        st.add((a,b))
x=0
while x<n-1:
    if s[x] in g and s[x+1] not in g and (s[x],s[x+1]) in st:
        aux=s[x]
        s[x]=s[x+1]
        s[x+1]=aux
        x=max(x-1,0)
    else:
        x+=1
ans=0
for i in range(n-2,-1,-1):
    if s[i] in g:
        ans+=1
    else:
        break
print(ans)
