a,b=list(map(int,input().split()))
p=list(map(int,input().split()))
l=[]
for i in range(b):
        l.append(list(map(int,input().split())))
p=p[: :-1]
s=0
mu=-1
while(len(p)>1):
        f=0
        if mu==p[1]:
                break
        else:
                mu=p[1]
        for j in range(len(l)):
                if(p[0]==l[j][1] and p[1]==l[j][0]):
                        l.remove(l[j])
                        s+=1
                        p.remove(p[1])
                        f=1
                        break
        if(f==0):
                for i in range(1,len(p)):
                        f=0
                        for j in range(len(l)):
                                if(p[i]==l[j][1] and p[i+1]==l[j][0]):
                                        k=p[i]
                                        p[i]=p[i+1]
                                        p[i+1]=k
                                        f=1
                                        l.remove(l[j])
                                        break
                                        
                        if(f==0):
                                break
print(s)
