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

pupils = list(map(int, input().split(" ")))

pairs = []
for i in range(m):
    pairs.append(tuple(map(int,input().split(" "))))
can_pass = []
for pair in pairs:
    if pair[1] == pupils[-1]:
        can_pass.append(pair)

count = len(can_pass)
reachable = []
for pass_pair in can_pass:
    reach = True
    for j in range(n - 2, -1, -1):
        if pupils[j] == pass_pair[0]:
            break
        else:
            for pair in pairs:
                found = False
                if pair[0] == pass_pair[0] and pair[1] == pupils[j]:
                    found = True
                    break
            if not found:
                reach = False
                break
    if not reach:
        count = count - 1

print(count)
