from sys import stdin,stdout
n,m=map(int,stdin.readline().split())
p=list(map(int,stdin.readline().split()))
pairs=[None]*(n+1)
for i in range(n+1):
         pairs[i]=set()
for i in range(m):
         x,y=map(int,stdin.readline().split())
         pairs[x].add(y)
         pairs[y].add(x)
x=p[n-1]
ans=0
for i in range(n-2,-1,-1):
         if p[i] in pairs[x]:
                  ans+=1
         else:
                  for j in range(i-1,-1,-1):
                           if p[j] in pairs[x]:
                                    y=p[j]
                                    flag=True
                                    for k in range(j+1,i):
                                             if p[k] not in pairs[y]:
                                                      flag=False
                                                      break
                                    if(flag):
                                             ans+=1
                                    break
                  break
stdout.write(str(ans))