n, m = map(int, input().split())
q = [n] * (n + 1)
for i, p in enumerate(input().split()):
    q[int(p)] = i
r = [{n + 1} for _ in range(n + 1)]
for _2 in range(m):
    u, v = map(int, input().split())
    if q[u] < q[v]:
        r[u].add(v)
res = 1
for i in range(1, n + 1):
    if q[i] < n - 1 and len(r[i]) + q[i] == n:
        res += 1
print(res - 1)
