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]

for i in range(m):
    u,v=map(int,input().split())
    adj[u].add(v)
s=set()
an=0
for i in range(n-2,-1,-1):
    if xx in adj[a[i]]:
        if len(adj[a[i]])<len(s) or any([j not in adj[a[i]] for j in s ]):
            print(an)
            break
        else:
            an+=1
    else:
        s.add(a[i])
else:
    print(an)