(* Autor: Slobodan Mitrovic *)
program sumarum;
var
	mmax, mmin, a : array [0 .. 499999] of longint;
	n, k, i, idxLeft, idxRight, ret : longint;
  f : text;
  
function max(x, y : longint) : longint;
begin
	if (x > y) then
		max := x
	else
		max := y;
end;

function min(x, y : longint) : longint;
begin
	if (x < y) then
		min := x
	else
		min := y;
end;

begin
	assign(f, 'sumarum.in');
	reset(f);
	readln(f, n, k);
  for i := 0 to n - 1 do
  	read(f, a[i]);
    
  mmax[n - 1] := a[n - 1];
  for i := n - 2 downto 0 do
		mmax[i] := max(a[i], mmax[i + 1]);
      
  mmin[0] := a[0];
  for i := 1 to n - 1 do
    mmin[i] := min(a[i], mmin[i - 1]);
        
  idxLeft := 0;
  idxRight := n - k - 1;
  ret := -1000000000;
  for i := 0 to k do
  	begin
      ret := max(ret, mmax[idxRight] - mmin[idxLeft]);
      inc(idxLeft);
      inc(idxRight);
    end;
  
  dec(idxRight);
  dec(idxLeft);
  assign(f, 'sumarum.sol');
  rewrite(f);
  writeln(f, ret);
  close(f);
end.
