#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];
		}
	}

	for(int i =0;i<rows;i++){
		if(i%2==0){
				for(int j =0;j<cols;j++){
			cout<<arr[i][j]<<" ";
		}
		}
		else{
			for(int j=cols-1;j>=0;j--){
				cout<<arr[i][j]<<" ";
			}
		}
	
		cout<<endl;
	}
	
	
	return 0;
}