
from collections import defaultdict
n,m = map(int,input().split())

l = list(map(int,input().split()))

posn = defaultdict(int)
ha = set()
hash = defaultdict(set)
for j,i in enumerate(l):
    posn[i] = j+1
for i in range(m):
    a,b = map(int,input().split())
    ha.add((a,b))
    hash[a].add(b)


count = 0
z = l[-1]
j = n-1

while True:
    z = j-1

    if z>=0:
        if (l[z],l[j]) in ha:


          l[z],l[j] = l[j],l[z]
          j-=1
          count+=1
        else:
            break
    else:
        break


if  j == 0:
    print(count)
else:
    seti = set()

    while j>=0:
        # print(seti)
        if seti == set():
            seti.add(l[j])
            j-=1
        else:
            flag = 0
            for x in seti:
                if m not in hash[l[j]]:
                    flag = 1
                    break
            if flag == 0:
             j-=1
             count+=1
            else:
                seti.add(l[j])
                j-=1

    print(count)




