n, m = map(int, input().split())
p = [int(i) - 1 for i in input().split()]
not_pass = set()
t = [set() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    t[a - 1].add(b - 1)

for ell in p[-2::-1]:
    # print(ell)
    k = 0
    for el in t[ell]:
        if el in not_pass:
            k += 1
    if k != len(not_pass) or p[-1] not in t[ell]:
        not_pass.add(ell)

print(n - 1 - len(not_pass))
# print(not_pass)