import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int M = sc.nextInt();
int N = sc.nextInt();
int[][] arr = null;
if ((M > 1 && N > 1) && (M < 10 && N < 10)) {
arr = new int[M][N];
for (int row = 0; row < arr.length; row++) {
for (int col = 0; col < N; col++) {
arr[row][col] = sc.nextInt();
}
}
int col = 0;
for (; col <= arr.length - 1;) {
if (col % 2 == 0) {
int row = 0;
for (; row <= arr.length - 1;) {
System.out.print(arr[row][col] + ", ");
row++;
}
} else {
int row = arr.length - 1;
for (; row >= 0; row--) {
System.out.print(arr[row][col] + ", ");
}
}
col++;
}
System.out.println("END");
}
}
}