from collections import defaultdict

a,b=map(int,input().split())
p=list(map(int,input().split()))
d=defaultdict(list)
for i in range(b):
        l=list(map(int,input().split()))
        d[l[0]].append(l[1])
l=[]
place=0
for i in range(a-1,0,-1):
        l.append(p[i])
        f=0
        for el in l:
                if el not in d[p[i-1]]:
                        f=1
                        break
        if(f==0):
                place+=1
                i+=1
print(place)