n, m = map(int, input().split())
pos = list(map(int, input().split()))
pos.reverse()
h = {}
for i in range(n):
    h[i + 1] = []
for i in range(m):
    q, w = map(int, input().split())
    h[q].append(w)
nastya = pos.pop(0)
ass = -1
g = 0
for i in pos:
    if nastya in h[i] and (ass in h[i] or ass == -1):
        g += 1
    elif ass == -1:
        ass = i
    else:
        break
print(g)
