program train;
var
a,b:array[1..100]of integer;
n,m,i,max,x,r,ans:integer;
g:array[1..100]of boolean;
f:text;
procedure go(t:integer);
var i,j,k:integer;
ok:boolean;
begin
x:=x+1;g[t]:=false;
j:=0;
for i:=1 to n do
begin
if (b[t]<=a[i]) and g[i] then
begin
if j=0 then j:=i;
if j<>0 then if b[i]<b[j] then j:=i;
end;
end;
if j<>0 then go(j);
if j=0 then if max<x then max:=x;
end;
Begin
assign(f,'train.in');reset(f);
readln(f,n,m);
for i:=1 to n do readln(f,a[i],b[i]);
for i:=1 to n do g[i]:=true;
close(f);
max:=0;ans:=0;
x:=0;r:=0;
repeat
r:=r+1;max:=0;
for i:=1 to n do if g[i] then begin x:=0;go(i);g[i]:=true;end;
ans:=ans+max;
until r=m;
assign(f,'train.out');rewrite(f);
writeln(f,ans);close(f);
end.