import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int[][] array = new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
array[i][j]= scan.nextInt();
}
}
int top = 0;
int bottom = n-1;
int left =0;
int right = m-1;
int dir=1;
while(top<=bottom && left<=right){
if(dir==1){
for(int j =left;j<=right;j++){
System.out.print(array[top][j]+ ", “);
}
top++;
dir=2;
}
if(dir==2){
for(int row=top;row<=bottom;row++){
System.out.print(array[row][right]+”, ");
}
right--;
dir=3;
}
if(dir==3){
for(int col = right;col>=left;col--){
System.out.print(array[bottom][col]+", ");
}
bottom--;
dir=4;
}
if(dir==4){
for(int row = bottom; row>=top;row--){
System.out.print(array[row][left]+", ");
}
left++;
dir=1;
}
}
System.out.print("END");
}
}