N, M = map(int, input().split())
TP = [int(a) for a in input().split()]
INV = [-1] * N
for i in range(N):
    INV[TP[i]-1] = i


P = [i for i in range(N)]
print(INV)
IV = [i for i in range(N)]

L = []
LL = []
for _ in range(M):
    u, v = map(int, input().split())
    u, v = INV[u-1], INV[v-1]
    if u < v:
        if v == N-1:
            LL.append(u)
        else:
            L.append([u, v])

L = sorted(L, key = lambda x: x[0]*10**10-x[0])
LL = sorted(LL)

###
print("P=", P)
print("L=", L)
print("LL=", LL)

x = N-1
flg = 1
while x > 0 and flg:
    flg = 0
    while LL[-1] == P[x-1]:
        IV[N-1] = x-1
        IV[P[x-1]] = x
        x -= 1
        LL.pop()
        if len(LL) == 0:
            break
    
    if len(L) == 0:
        break
        
    a, b = L.pop()
    y = IV[b]
    if y >= 1 and P[y-1] == a:
        P[y-1] = b
        P[y] = a
        IV[a] = y
        IV[b] = y-1
        flg = 1
    
print(N-1-x)
