import sys
import heapq
import math
from enum import Enum

lines = sys.stdin.read().splitlines()
n, m = map(int, lines[0].split(' '))
positionToNumber = [int(x)-1 for x in lines[1].split(' ')]

numberToPosition = [0]*n
for i in range(0, len(positionToNumber)):
    numberToPosition[positionToNumber[i]] = i

# print('numberToOrder: ' + str(numberToOrder))
bitmaps = [0]*n
for i in range(0, m):
    a, b = list(map(int, lines[i+2].split(' ')))
    # a lets b in front
    indexA = a-1
    indexB = b-1
    bitmaps[numberToPosition[indexA]]|=(1<<(n-1-numberToPosition[indexB]))

# print(bitmaps)
count = 0
mask = 1<<n-1
for i in reversed(range(0, n-1)):
    if (bitmaps[i]&mask&(2**(n-i-1)-1))==mask&(2**(n-i-1)-1):
        mask^= (1<<(n-i-1))
        count += 1
print(count)
