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