import os
from io import BytesIO

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())


n, m = mi()
p = li()
ok = [set() for _ in range(n+1)]
for _ in range(m):
    u, v = mi()
    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)