window.document.write("");
#include <bits/stdc++.h>
using namespace std;
void YueSeFu(int n, int m);
int main(int argc, char** argv)
{
	YueSeFu(10, 3);
	return 0;
}
void YueSeFu(int n, int m)
{
	bool a[n+1];
	int j=1,r=0;
	memset(a,false,sizeof(a));
	for(int k=1; k<=n; k++)
	{
		j=r;
		if(k==1)
			j=0;
		int p=0;
		for(int i=1; i<=n; i++)
		{

			if(a[i]!=true)
				j+=1;
			else
				p+=1;
			if(j%m==0)
			{
				a[j+p-r]=true;
				cout<<j+p-r<<" ";
			}
		}
		cout<<endl;
		r=j%m;
	}


//	cout<<a[i]<<" ";
}