program ex;
type
ss=array[1..10]of integer;
var
a,c:ss;
b:array[1..100,1..100]of integer;
f1,f2:text;
i,j:integer;
n,m:integer;
t:integer;
flag:boolean;
procedure init;
begin
assign(f1,'dataa.in');
assign(f2,'dataa.out');
reset(f1);
rewrite(f2);
readln(f1,n,m);
for i:=1 to n do a[i]:=i;
end;
function f(a:ss):boolean;
var
flag:boolean;
i,x:integer;
begin
x:=0;
flag:=true;
for i:=1 to m-1 do
if a[i+1]<a[i] then
begin
flag:=false;
break;
end;
for i:=1 to m do x:=x+a[i];
if (flag=true)and(x=n) then f:=true
else f:=false;
end;
procedure zh(step:integer);
var
i,j,k:integer;
begin
for i:=1 to n do
begin
c[step]:=a[i];
j:=i;
if step<m then zh(step+1)
else begin
flag:=f(c);
if flag=true then
begin
inc(t);
for k:=1 to m do b[t,k]:=c[k];
end;
end;
end;
end;
begin
init;
zh(1);
writeln(f2,t);
for i:=1 to t do
begin
for j:=1 to m do
write(f2,b[i,j],' ');
writeln(f2);
end;
close(f1);
close(f2);
end.