import sys,math
from fractions import gcd
from collections import defaultdict
from io import BytesIO
import hashlib
sys.stdin = BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
#n = int(input())
n,m = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
arr = arr[::-1]
ds = defaultdict(set)
for _ in range(m):
    a,b = [int(x) for x in input().split(' ')]
    ds[b].add(a)

#print(ds)

prep = set()
nast = arr[0]
res = 0
for i in range(1,n):
    if arr[i] in ds[nast]:
        fl = 1
        for el in prep:
            if arr[i] not in ds[el]:
                fl = 0
                break
        if fl == 0:
            prep.add(arr[i])
        else:
            res += 1
    else:
        prep.add(arr[i])
print(res)