var
x,y:array[1..1000]of longint;
a:array[1..1000]of boolean;
n,m,i,j,zong:longint;
begin
assign(input,'hal4d.in');reset(input);
assign(output,'hal4d.out');rewrite(output);
read(n,m);fillchar(a,sizeof(a),true);
fillchar(x,sizeof(x),0);y:=x;
for i:=1 to m do
begin
read(x[i],y[i]);
for j:=1 to i-1 do
if a[j]=true then
begin
if (x[j]>=x[i]) and (y[j]<=y[i]) then begin a[j]:=false;break;end;
if (x[j]>=x[i]) and (x[j]<=y[i]) and (y[j]>y[i]) then x[j]:=y[i]+1;
if (x[j]<x[i]) and (y[j]>=x[i]) and (y[j]<=y[i]) then y[j]:=x[i]-1;
end;
end;
for i:=1 to m do if a[i]=true then zong:=zong+1;
writeln(zong);
close(input);close(output);
end.