program razgovori;

var
   n, m, i, p, x, l, r, br : longint;
   raz : array[1 .. 5000000] of longint;

function max (a, b : longint) : longint;
begin
   if a>b then max := a else max := b;
end;

begin
   readln (n, m);
   for i := 1 to n do
      readln (p, raz[p]);
   p := 0;
   repeat
      Inc (p);
   until raz[p]<>0;
   x := raz[p];
   for i := p+1 to m do
      if raz[i]<>0 then begin
         l := i;
         repeat
            Dec (l);
         until raz[l]<>0;
         r := i;
         repeat
            Inc (r);
         until (raz[r]<>0) or (r=m);
         br := max (raz[l], raz[r]);
         if x<br then x := br;
         if br<raz[i] then x := x+raz[i]-br;
      end;
   writeln (x);
end.
