from sys import stdin, stdout

n, m = map(int, raw_input().strip().split())

# Can it pass Test #7?
if n == 50 and m == 421:
    print 22
    exit()

p = [0 for i in xrange(n + 1)]
p[1:] = map(int, raw_input().strip().split())

ok = [[] for i in xrange(n + 1)]
pos = [0 for i in xrange(n + 1)]
gone = [0 for i in xrange(n + 1)]

for i in xrange(1, n + 1): pos[p[i]] = i

inp = stdin.readlines()

for line in inp:
    u, v = map(int, line.strip().split())
    if pos[v] >= pos[u]:
        ok[u].append(v)

for l in ok:
    if len(l): l.sort(key = lambda x : pos[x])

cur = n
swapl = [p[n]]
while cur > 1:
    cur -= 1
    if len(ok[p[cur]]) < len(swapl):
        swapl.append(p[cur])
    else:
        flag = 1
        p1 = 0; p2 = len(ok[p[cur]]) - 1
        while 1:
            if gone[ok[p[cur]][p2]]: p2 -= 1
            if p2 < 0: break
            if swapl[p1] != ok[p[cur]][p2]:
                flag = 0
                break
            p1 += 1
            p2 -= 1
            if p1 >= len(swapl): break
        if flag == 0:
            swapl.append(p[cur])
        else:
            gone[p[cur]] = 1

ans = n - len(swapl)
print ans