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