#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')


def gcd(x, y):
    """ greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x


def main():
    n, m = map(int, input().split())
    p = [int(i) - 1 for i in input().split()]
    pos = p[-1]

    graph = [set() for _ in range(n)]
    for i in range(m):
        u, v = map(int, input().split())
        graph[u - 1].add(v - 1)

    for i in range(n - 2, -1, -1):
        while (i + 1 < n) and (p[i + 1] in graph[p[i]]):
            p[i], p[i + 1] = p[i + 1], p[i]
            i += 1

    print(n - p.index(pos) - 1)


if __name__ == '__main__':
    main()
