n, p = list(map(int,input().split()))
initial = list(map(int,input().split()))
parent = [i for i in range(n + 1)]

pairs = [ list(map(int,input().split())) for i in range(p)]
pairs = set([(a[0], a[1]) for a in pairs])

def find(x):
	if x == parent[x]:
		return x
	else:
		parent[x] = find(parent[x])
		return find(parent[x])
def Union(x,y):
  a = find(x)
  b = find(y)
  parent[a] = b
nadya = initial[n-1]
swapki = [0] * (n+1)
for pair in pairs:
	if pair[1] == nadya:
		swapki[pair[0]] = 1
przechodzace = []
wyn = 0
for i in range(1, n):
	if swapki[initial[n - i - 1]] == 1:
		j = n - i - 1 + 1
		while(j < n):
			if (initial[n - i - 1], initial[j]) not in pairs and find(initial[j]) != 0:
				break
			if find(initial[j]) == 0:
				j = n 
				break
			j += 1
		if j == n:
			przechodzace.append(initial[n - i - 1])
			Union(initial[n - i - 1],0)
			wyn += 1
print(wyn)
#print(parent)
