n, m = map(int, input().split())
g=[int(g) for g in input().split()]
swap=set()
last={g[-1]}
for i in range(m):
    swap.add(tuple(map(int, input().split())))
g=g[::-1]
for pupil in g[1:]:
    
    for x in last:
        if (pupil,x) not in swap:
            last.add(pupil)
            break
print(n-len(last))
    
    
