n,m = map(int,input().split())
l = list(map(int,input().split()))
d=l[-1]
f= list()
ans=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]

    
print(ans)
    