import sys
input = sys.stdin.readline

n, m = map(int, input().split())
p = list(map(int, input().split()))
ok = [set() for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, input().split())
    ok[u].add(v)
ans = 0
s = {p[n-1]}
for i in range(n-2, -1, -1):
    if s <= ok[p[i]]:
        ans += 1
    else:
        s.add(p[i])
print(ans)