#include<stdio.h>
int main(){
    int m, n;
    scanf("%d",&m);
    scanf("%d",&n);
    if(m<=0||n<=0)
    {
        printf("-1");
    }
    int a[100][100];
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    int top=0;bottom=m-1,left=0,right=n-1;
    while(top<=bottom&&left<=right)
    {
        for(int i=left;i<=right;i++)
        {
            printf("%d ",a[top][i]);
        }
        top++;
        for(int i=top;i<=bottom;i++)
        {
            printf("%d ",a[i][right]);
        }
        right--;
        if(top<=bottom)
        {
            for(int i=rigth;i>=left;i--)
            {
                printf("%d ",a[bottom][i]);
            }
            bottom--;
        }
        if(left<=right)
        {
            for(int i=bottom;i>=top;i--)
            {
                printf("%d ",a[i][left]);
            }
            left++;
        }
    }
}