#include<iostream>
#include<vector>
using namespace std;
int main()
{
int r, c,p=0,key = 0;
while (cin >> r >> c)
{
vector<int>data(r*c , 0);
for (int i = 0; i < data.size(); i++)
cin >> data[i];
int i=0,count=0;
if (data.size() % 2 == 0)
key = data.size()/2;
else
key = data.size() / 2 + 1;
for (; i <=key; i++)
{
count = i;
for (; count < data.size(); count += c)
{
p = data[count];
cout << p<<" ";
}
cout << endl;
if (c == 1)
break;
if (p == data[r*c-1])
break;
}
key = 0;
}
}