import sys
input = sys.stdin.readline
print = sys.stdout.write
n,m=map(int,input().split())
q=list(map(int,input().split()))
pos={}
for i in range(n):
	pos[q[i]-1]=i
drt={}
for i in range(n):
	drt[i]=0
part=set()
for i in range(m):
	u,v=map(int,input().split())
	if pos[u-1]<pos[v-1]:
		drt[u-1]+=1
	if v==q[-1]:
		part.add(pos[u-1])
b=[0 for i in range(n)]
for i in part:
	b[i]=1
ans=0;l=0
for i in range(n-1,-1,-1):
	if b[i]==1 and drt[q[i]-1]>=n-1-pos[q[i]-1]-l:
		l+=1
		ans+=1
 
print(str(ans))