import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():

    n, m = map(int, input().split())
    P = list(map(int, input().split()))
    P = [p-1 for p in P]
    x = P[-1]
    U = set()
    g = [set() for i in range(n)]
    for i in range(m):
        u, v = map(int, input().split())
        u, v = u-1, v-1
        if v == x:
            U.add(u)
        g[u].add(v)

    if n == 1:
        print(0)
        exit()

    S = P[0:-1]
    for i in range(len(S)-1):
        if S[i] in U:
            if S[i+1] in g[S[i]]:
                S[i], S[i+1] = S[i+1], S[i]
    #print(S)
    ans = 0
    while S:
        if S[-1] in U:
            ans += 1
            S.pop()
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()
