n,m = map(int,input().split())
a = list(map(int,input().split()))
b = []
c = []
d = []
for i in range(m):
    q = list(map(int,input().split()))
    b.append(q[0])
    c.append(q[1])
    d.append(q)
i = 0
z = a[len(a) - 1]
while i < len(a) - 1:
    qq = [a[i],a[i + 1]]
    if qq in d:
        a[i],a[i + 1] = a[i + 1],a[i]
    i = i + 1
ccc = 0
cc = len(a) - a.index(z)
zz = []
i = 0
zy = []

while a[i] != z:
    zz.append(a[i])
    i = i + 1
zz.sort()
for i in range(len(b)):
    if c[i] == 2:
        zy.append(b[i])
cccc = len(list(set(zz).intersection(zy)))
print(cc - 1 + cccc)