#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	// your code goes here
	int rows,cols; cin>>rows>>cols;
	vector<vector<int>>arr(rows,vector<int>(cols));
	for(int i =0;i<rows;i++){
		for(int j =0;j<cols;j++){
			cin>>arr[i][j];
		}
	}
	int i=0;int j =0;
	while(j<cols){
		
		cout<<arr[i][j]<<" ";
		j++;
		
	}
	j =cols-2;
	i++;
	cout<<endl;
	while(i<rows-1 && j>0){
		cout<<arr[i][j]<<endl;
		i++;
		j--;
		
	}

	while(j<cols){
		cout<<arr[i][j] <<" ";
		j++;
	}
	
	return 0;
}