n, m = map(int, input().split())

c = 0

q = list(map(int, input().split()))

for i in range(m):
    u, v = map(int, input().split())

    j = q.index(u)

    if j + 1 < n and q[j + 1] == v:
        c += 1

print(c)