n,m = map(int,input().split())
l = list(map(int,input().split()))
d=l[-1]
f= list()
p=list()
ans=0
r=0
for i in range(m):
    q,r=map(int,input().split())
    f.append((q,r))
for i in range(1,n):
    if (l[-i-1],l[-i]) in f and l[-i-1]!=d:
        ans=ans+1
        l[-i],l[-1-i]=l[-i-1],l[-i]
        if (l[-i],l[-i+1]) in f and l[-i]!=d:
            l[-i],l[-i+1]=l[-i+1],l[-i]
for i in range(n):
    if l[i]==d:
        print(n-1-i)
        break
    
        
    