#include<bits/stdc++.h>
using namespace std;
int main() {
int row,col;
cin>>row>>col;
int a[row][col];
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
cin>>a[i][j];
}
}
int cs=0,ce=col-1,rs=0,re=row-1;
while(re>=rs && ce>=cs){
for(int i=ce;i>=cs;i--){
cout<<a[rs][i]<<" ";
}
rs++;
for(int i=rs;i<=re;i++){
cout<<a[i][cs]<<" ";
}
cs++;
for(int i=cs;i<=ce;i++){
cout<<a[re][i]<<" ";
}
re--;
for(int i=re;i>=rs;i--){
cout<<a[i][ce]<<" ";
}
ce--;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJaW50IHJvdyxjb2w7CiAgICBjaW4+PnJvdz4+Y29sOwogICAgaW50IGFbcm93XVtjb2xdOwogICAgZm9yKGludCBpPTA7aTxyb3c7aSsrKXsKICAgIAlmb3IoaW50IGo9MDtqPGNvbDtqKyspewogICAgCQljaW4+PmFbaV1bal07CiAgICAJfQogICAgfQoJaW50IGNzPTAsY2U9Y29sLTEscnM9MCxyZT1yb3ctMTsKCXdoaWxlKHJlPj1ycyAmJiBjZT49Y3MpewoJCQoJCWZvcihpbnQgaT1jZTtpPj1jcztpLS0pewoJCQljb3V0PDxhW3JzXVtpXTw8IiAiOwoJCX0KCQlycysrOwoJCWZvcihpbnQgaT1ycztpPD1yZTtpKyspewoJCQljb3V0PDxhW2ldW2NzXTw8IiAiOwoJCX0KCQljcysrOwoJCWZvcihpbnQgaT1jcztpPD1jZTtpKyspewoJCQljb3V0PDxhW3JlXVtpXTw8IiAiOwoJCX0KCQlyZS0tOwoJCWZvcihpbnQgaT1yZTtpPj1ycztpLS0pewoJCQljb3V0PDxhW2ldW2NlXTw8IiAiOwoJCX0KCQljZS0tOwoJfQoJcmV0dXJuIDA7Cn0=