(N,M),*P=$<.map{|l|l.split.map &:to_i};
P.sort_by!{|l,r|r-l};
#p P
b=[i=0]*-~M;
M.times{|x|
[[$L,1],[$R+1,-1]].map{|j,v|
#p [:j,j,v,b]
(b[j]+=v;j+=j&-j)until j>M
}while($L,$R=P[i];$R&&$R-$L<=x&&i+=1);
#p b
k=N-i;
0.step(M,x+1){|j|(k+=b[j];j-=j&-j)while j>0};
#0.step(M,x+1){|j|k+=b[j]while(j-=j&-j)>0};
p k;
}


__END__

[[[[]0]1 []2]3 [[]4]5 []6]7

