const gmaxc=400;
nmaxc=200;
var tomb:array[0..gmaxc,0..nmaxc] of word;
hany:array[1..nmaxc] of word;
t:text;
N,G,i,al,j,co,u:longint;
begin
assign(t,'ghiozdan.in');
reset(T);
read(t,N);
read(t,G);
co:=1;
read(t,tomb[0,1]);
hany[1]:=1;
for i:=2 to n do begin
read(t,j);
if j=tomb[0,1] then inc(hany[co]) else
begin
inc(co);
hany[co]:=1;
tomb[0,co]:=j;
end;
end;
closE(T);
for i:=1 to gmaxc do for j:=1 to nmaxc do tomb[i,j]:=0;
i:=0;
for al:=1 to g do begin
inc(i);
j:=0;
while (j<n) and ((tomb[i,0]>2) or (tomb[i,0]=0)) do
begin
inc(j);
co:=i-tomb[0,j];
if co>0 then begin if (tomb[co,j]<hany[j]) and (tomb[co,0]>0) then
if ((tomb[co,0]+1)<tomb[i,0]) or (tomb[i,0]=0) then
begin
for u:=0 to n do tomb[i,u]:=tomb[co,u];
tomb[i,j]:=tomb[i,j]+1;
inc(tomb[i,0]);
end;
end
else
if co=0 then begin
for u:=0 to n do tomb[i,u]:=0;
tomb[i,j]:=1;
inc(tomb[i,0]);
end;
if al mod 200=0 then begin
for j:=200 to 400 do
for co:=0 to 200 do
tomb[j-200+1,co]:=tomb[j,co];
i:=i-200;
end;
end;
end;
u:=g;
while tomb[u,0]=0 do u:=u-1;
assign(t,'ghiozdan.out');
rewrite(T);
write(t,u,' ');
writeln(t,tomb[u,0]);
for i:=1 to n do
if tomb[u,i]>0 then
for j:=1 to tomb[u,i] do
writeln(t,tomb[0,i]);
close(t);
end.