package challenges_CB_2;
import java.util.Scanner;
public class Wave_print {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int a [][] = new int[n][m];
for(int i=0; i<n;i++) {
for(int j =0; j<m; j++) {
a[i][j] = sc.nextInt();
}
}
printWave(a);
}
public static void printWave(int[][]a) {
for(int row = 0;row<a.length;row++) {
if(row%2==0) {
for(int k =0 ; k<a[row].length;k++) {
System.out.print(a[k][row]+", ");
}
}else {
for(int k = a[row].length-1;k>=0;k--) {
System.out.print(a[k][row]+", ");
}
}
}
System.out.println("END");
}
}