import os
from io import BytesIO

s = os.read(0, os.fstat(0).st_size)
inp = []
numb = 0
 
for i in range(len(s)):
    if s[i]>='0':
        numb = 10*numb + ord(s[i])-48
    else:
        if s[i]!='\r':
            inp.append(numb-1)
            numb = 0
if s[-1]>='0':
    inp.append(numb-1)
ii = 0

n,m = inp[ii]+1,inp[ii+1]+1
ii+=2
P = inp[ii:ii+n]
ii+=n

pos = [-1]*n
for i in range(n):
    pos[P[i]] = i

nast = P[-1]
coupl = [set() for _ in range(n)]

for _ in range(m):
    u,v = inp[ii],inp[ii+1]
    ii+=2

    coupl[u].add(v)


for special in sorted(coupl[nast],key = lambda i:pos[i],reverse=True):
    x = pos[special]
    while x+1<n and P[x+1] in coupl[special]:
        pos[special] += 1
        pos[P[x+1]] -= 1

        P[x],P[x+1]=P[x+1],P[x]
        x+=1

print n-1 - pos[nast]