#include
using namespace std;
void spiralPrintClockWise( int arr[][100], int row, int col){
int sc=0, ec=col-1;
int sr=0, er=row-1;
while(sc<=ec and sr<=er){
for(int startrow=sc;startrow<=ec;startrow++){
cout<<arr[sr][startrow]<<", ";
}
sr++;
for(int endcolumn=sr;endcolumn<=er;endcolumn++){
cout<<arr[endcolumn][ec]<<", ";
}
ec--;
if(sr<er) {
for(int endrow=ec;endrow>=sc;endrow--){
cout<<arr[er][endrow]<<", ";
}
er--;
}
if(sc<ec){
for(int startcolum=er;startcolum>=sr;startcolum--){
cout<<arr[startcolum][sc]<<", ";
}
sc++;
}
}
cout<<"END";
}
int main() {
int crow,ccol;
cin>>crow>>ccol;
int arr[100][100];
for(int i=0;i<crow;i++){
for(int j=0;j<ccol;j++){
cin>>arr[i][j];
}
}
spiralPrintClockWise(arr,crow,ccol);
return 0;
}