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]
    g = [[] for i in range(n)]
    for i in range(m):
        u, v = map(int, input().split())
        u, v = u-1, v-1
        g[u].append(v)

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

    S = P[0:-1]

    #print(g)

    ans = 0
    Q = {x}
    while S:
        y = S[-1]
        cnt = 0
        for z in g[y]:
            if z in Q:
                cnt += 1
        if cnt == len(Q):
            ans += 1
        else:
            Q.add(y)
        S.pop()
    #print(Q)
    print(ans)

if __name__ == '__main__':
    main()
