import sys
import heapq
import math
from enum import Enum

lines = sys.stdin.read().splitlines()
n, m = map(int, lines[0].split(' '))
order = list(map(int, lines[1].split(' ')))

numberToOrder = [0]*n
for i in range(0, len(order)):
    numberToOrder[order[i]-1] = i

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

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