from bisect import bisect_left
n, m = map(int, input().split())
xs = list(map(int, input().split()))
x = [(0, 0)] + [(xs[i], i + 1) for i in range(n)]
x = sorted(x)
prefmin = [0] * (n + 1)
prefmax = [0] * (n + 1)
for i in range(n + 1):
prefmin[i] = x[i][1]
prefmax[i] = x[i][1]
if(i > 0):
prefmin[i] = min(prefmin[i], prefmin[i - 1])
prefmax[i] = max(prefmax[i], prefmax[i - 1])
sufmin = [0] * (n + 1)
sufmax = [0] * (n + 1)
for i in reversed(range(n + 1)):
sufmin[i] = x[i][1]
sufmax[i] = x[i][1]
if(i != n):
sufmin[i] = min(sufmin[i], sufmin[i + 1])
sufmax[i] = max(sufmax[i], sufmax[i + 1])
ans = 0
for i in range(m):
a, b = map(int, input().split())
if (a < b):
pref = bisect_left(x, (a, n + 1)) - 1
suf = bisect_left(x, (b, -1))
if (pref >= 0 and suf <= n and prefmin[pref] < sufmax[suf]):
ans += 1
else:
pref = bisect_left(x, (b, n + 1)) - 1
suf = bisect_left(x, (a, -1))
if (pref >= 0 and suf <= n and sufmin[suf] < prefmax[pref]):
ans += 1
print(ans)