#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n>>m;
    
    int arr[n][m];
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin >> arr[i][j];
        }
    }
    
    int ans[n][m];
    int left=0;
    int right=m-1,top=0,bottom=n-1;
    
    while(top<=bottom && left<=right)
    {
        for(int i=left;i<=rigth;i++)
        {
            cout<<arr[top][i]<<" ";
        }
        top++;
        for(int i=top;i<=bottom;i++)
        {
            cout<<arr[i][right]<<" ";
        }
        right--;
        for(int i=right;i<=left;i++)
        {
            cout<<arr[bottom][i]<<" ";
        }
        bottom--;
        for(int i=bottom;i<=top;i++)
        {
            cout<<arr[i][left]<<" ";
        }left++;
    }
}