from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest, heapify, heappop ,heappush, heapreplace
from math import ceil,floor,log,log2,sqrt,gcd,factorial,pow,pi
from bisect import bisect_left,bisect_right

def binNumber(n,size=4):
    return bin(n)[2:].zfill(size)

def iar():
    return list(map(int,input().split()))

def ini():
    return int(input())

def isp():
    return map(int,input().split())

def sti():
    return str(input())

def par(a):
    print(' '.join(list(map(str,a))))

def tdl(outerListSize,innerListSize,defaultValue = 0):
    return [[defaultValue]*innerListSize for i in range(outerListSize)]

def sts(s):
    s = list(s)
    s.sort()
    return ''.join(s)

def bis(a, x):
    i = bisect_left(a, x) 
    if i != len(a) and a[i] == x: 
        return [i,True]
    else: 
        return [-1,False]

class pair:
    def __init__(self,f,s):
        self.fi = f
        self.se = s
    def __lt__(self,other):
        return (self.fi,self.se) < (other.fi,other.se)

#  =========     /\       /|    |====/|
#      |        /  \       |    |   / |
#      |       /____\      |    |  /  |
#      |      /      \     |    | /   |
#  ========= /        \  =====  |/====|  
#  code

if __name__ == "__main__":
    n,m = isp()
    p = [[]]*(n+1)
    a = iar()
    q = [[]]*(n+1)
    k = a[n-1]
    for i in range(m):
        x,y = isp()
        p[y].append(x)
        q[x].append(y)
    for i in range(1,n+1):
        p[i].sort()
        q[i].sort()
    i = n-1

    sw = True
    while sw:
        if i == 0:
            print(n-1)
            quit()
        if bis(p[a[i]],a[i-1])[1]:
            a[i],a[i-1] = a[i-1],a[i]
            i -= 1
            sw = True
            #print(100)
        else:
            j = i-1
            sw = False
            while j >= 1 and j<n:
                if bis(p[a[j]],a[j-1])[1]:
                    a[j],a[j-1] = a[j-1],a[j]
                    j += 1
                    sw = True
                    #print(100,j-1,j-2)
                else:
                    j -= 1
            for x in range(n):
                if a[x] == k:
                    i = x
                    break
    print(n-i-1)