var h:array[1..100000] of boolean;
m:array[1..100000] of longint;
a:array[1..100000] of longint;
i,j,l,r,n,s,p,li,ri:longint;
begin
assign(input,'bg.in');
reset(input);
assign(output,'bg.out');
rewrite(output);
readln(n,p);
for i:=1 to n do
read(a[i]);
for i:=1 to p do
begin
readln(l,r);
for j:=l to r do
begin
h[j]:=true;
m[j]:=m[j]+1;
end;
end;
for i:=1 to n do
if h[a[i]] then begin
begin
for j:=a[i] downto 1 do
if not(h[j]) or (m[j]<>m[a[i]]) then begin li:=j+1;break;end;
for j:=a[i] to 100000 do
if not(h[j]) or (m[j]<>m[a[i]]) then begin ri:=j-1;break;end;
for j:=li to ri do
if m[j]=1 then begin m[j]:=0;h[j]:=false; end
else
m[j]:=m[j-1];
end;
s:=s+1;
end;
writeln(s);
close(input);
close(output);
end.