n,m=map(int,input().split())
l=[int(x) for x in input().split()]
pairs=[]
for i in range(m):
    pairs.append([int(x) for x in input().split()])
pos=n-1
#print(l,pairs)
while 1:
    k=pos
    if [l[pos-1],l[pos]] in pairs:
        pos-=1
        k=pos
    elif k-2>=0 and [l[k-2],l[k-1]]in pairs:
        temp=l[k-1]
        l[k-1]=l[k-2]
        l[k-2]=temp
        k-=1
    else:
        break
print(n-1-pos)