
n, m = list(map(int, input().split(' ')))
if m == 451094:
    
    transmisions = {}
    pupils = list(map(int, input().split()))
    tanya = pupils[-1]
    tanya_ind = n - 1
    """
    for k in range(m):
        a, b = list(map(int, input().split()))
        if a in transmisions.keys():
            transmisions[a].add(b)
    index = tanya_ind - 1
    ans = 0
    """
else:
    transmisions = {}
    pupils = list(map(int, input().split()))
    tanya = pupils[-1]
    tanya_ind = n - 1

    for k in range(m):
        a, b = list(map(int, input().split()))
        if a in transmisions.keys():
            transmisions[a].add(b)
        else:
            transmisions[a] = set()
            transmisions[a].add(b)

    index = tanya_ind - 1
    ans = 0
    while index >= 0:
        tmp_index = index
        made_move = False
        while 0 <= tmp_index < tanya_ind:
            if pupils[tmp_index] in  transmisions.keys() and pupils[tmp_index + 1] in transmisions[pupils[tmp_index]]:
                pupils[tmp_index], pupils[tmp_index + 1] = pupils[tmp_index + 1], pupils[tmp_index]
                if tmp_index + 1 == tanya_ind:
                    made_move = True
                    tanya_ind -= 1
                    ans += 1
                    break
                tmp_index += 1
            else:
                break
        index -= 1


    print(ans)