R=lambda:list(map(int,input().split()))
def swap(a,b):
    try:
        x = 0
        x = queue[a]
        queue[a]=queue[b]
        queue[b]=x
        #print('True')
        return True
    except:
        pass
    #print('False')
    return False
n,m=R()
queue = []
queue = R()
able = [()]*m
for i in range(m):
    for x in R():able[i]+=x,;
Nastya=queue[n-1]
idx=queue.index(Nastya)
moves=1
while(moves>0):
    moves=0
    #print(queue)
    for i in range(len(able)):
        j=able[i][0]
        #print('checking ',j)
        #print(able[i][1])
        try:
            if(queue.index(Nastya)>queue.index(j)):
                if (queue[queue.index(j)+1]==able[i][1]):
                    if(swap(queue.index(j),queue.index(j)+1)):
                        moves+=1
                        #print('swapped')
        except:
            pass
print(idx-queue.index(Nastya))
