import sys
input = sys.stdin.readline

n, m = map(int, input().split())
p = list(map(int, input().split()))
ok = [[] for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, input().split())
    ok[u].append(v)
ans = 0
req = 1
mark = [0] * (n+1)
mark[p[n-1]] = 1
for i in range(n-2, -1, -1):
    cnt = sum(mark[v] for v in ok[p[i]])
    if cnt == req:
        ans += 1
    else:
        req += 1
        mark[p[i]] = 1
print(ans)