#include
using namespace std;
int main() {
int r,c;cin>>r>>c;int a[r][c];
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
cin>>a[i][j];
}
}
int sr=0,sc=0,er=r-1,ec=c-1;
while(sr<=er && sc<=ec){
for(int i=0;i<=ec;i++){
cout<<a[sr][i]<<","<<" ";
}
sr++;
for(int i=sr;i<=er;i++){
cout<<a[i][ec]<<","<<" ";
}
ec--;
for(int i=ec;i>=sc;i--){
cout<<a[er][i]<<","<<" ";
}
er--;
for(int i=er;i>=sr;i--){
cout<<a[i][sc]<<","<<" ";
}
sc++;
}
cout<<"END";
return 0;
}