# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
import collections
 
#Q = int(input())
 
#ans = [0]*Q
#s = input()
#N = len(s)
#arr = [int(x) for x in stdin.readline().split()]

N,M = [int(x) for x in stdin.readline().split()]
            
P = [int(x) for x in stdin.readline().split()]

idx = {}

for i in range(N):
    idx[P[i]] = i
    
swap = [0]*N

for i in range(M):
    x,y = [int(x) for x in stdin.readline().split()]
    
    A = idx[x]
    B = idx[y]
    
    if A<B:
        swap[A] += 1

k = N-1
#print(swap)
res = 0
for i in range(N-2,-1,-1):
    #print(swap[i],k)
    if swap[i]>= k-i:
        k -= 1
        
print(N-1-k)