if True:
    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)]
    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[1]*10**10+x[0])
    LL = sorted(LL)

else:
    INV = [1, 4, 0, 3, 2]
    N, M = 5, 2
    L = [[2, 3]]
    LL = [2]

F = [0] * N
for ll in LL:
    F[ll] = 1

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:
        if F[b] == 0 and F[a] == 1:
            P[y-1] = b
            P[y] = a
            IV[a] = y
            IV[b] = y-1
            flg = 1
    
print(N-1-x)