n,m=map(int,input().split())
li=list(map(int,input().split()))
ar=[]
for i in range(n-1):
    ar.append([li[i],li[i+1]])
uv=[]
for i in range(m):
    u,v=map(int,input().split())
    uv.append([u,v])
#print(uv)
#print(ar)
cnr=0
for i in range(len(uv)):
    for j in range(len(ar)):
        if uv[i][0]==ar[j][0] and uv[i][1]==ar[j][1]:
            cnr+=1
print(cnr)
            
    
    
