#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m,n,a[1000][1000],c,s;
int main () {
ios::sync_with_stdio (false);
cin.tie (nullptr);
cout.tie (nullptr);
cin >> n >> m;
for (int i=0;i<m;i++){
for (int j=0;j<n;j++){
cin>>a[i][j];
}
}
while (s<m*n){
for(int i=c;i<(m-c)&&s<m*n;i++){
cout<<a[i][c]<<" ";
s++;
}
for(int j=c+1;j<(n-c)&&s<m*n;j++){
cout<<a[m-2-c][j]<<" ";
s++;
}
for(int k=m-2-c;k>=c&&s<m*n;k--){
cout<<a[k][n-1-c]<<" ";
s++;
}
for(int h=n-2;h>=(1+c)&&s<m*n;h--){
cout<<a[c][h]<<" ";
s++;
}
c++;
}
return 0;
}