#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue
sys.setrecursionlimit(1000000)
#sys.stdin = open("input.txt", "r")

n, m = map(int, input().split())
q = list(map(lambda x: int(x)-1, input().split()))
nas = q[-1]
indx = [-1 for i in range(n)]
for i in range(n): indx[q[i]] = i
swp = [[] for i in range(n)]
fvr = []
for i in range(m):
	u, v = map(int, input().split())
	swp[u-1].append(v-1)
	if v-1 == nas:
		fvr.append(u-1)
for i in range(n): swp[i].sort(key = lambda x: indx[x])
fvr.sort(key=lambda x:indx[x], reverse=True)
for i in range(n): swp[i] = [i]+swp[i]

ans = 0
for i in range(len(fvr)):
	reach = False
	for j in range(1, len(swp[fvr[i]])):
		if indx[swp[fvr[i]][j]] != indx[swp[fvr[i]][j-1]]+1:
			False
			break
		if swp[fvr[i]][j] == nas:
			reach = True
			break
	if not reach:
		break
	ans += 1
print(ans)
