import java.util.*;
public class Main {
public static void main(String args[]) {
int n,m;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
m=sc.nextInt();
int[][] arr=new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
arr[i][j]=sc.nextInt();
}
}
waveprint(arr);
}
public static void waveprint(int[][] arr){
int j=0;
for(int i=0;i<arr.length;i++){
if(i%2==0){
for(j=0;j<arr[i].length;j++){
System.out.print(arr[j][i]+", ");}}
else{for(j=arr[i].length-1;j>=0;jβ){
System.out.print(arr[j][i]+", ");
}}}
System.out.print(βENDβ);
}
}