#include
using namespace std;
void spiralPrint(int a[][10],int n,int m){
// initialization of the 4 iterators;
int sr=0,sc=0;
int er=n-1,ec=m-1;
// condition till the loop works;
while(sc<=ec && sr<=er){// till they over shoot each other
// step 1 to print first row;
//print the sr from sc to ec
//sr++
for (int col=sc;col<=ec;col++){
cout<<a[sr][col]<<", ";
}
sr++;
// step 2 to print the last column
// print ec from sr to er;
// ec--;
for (int row=sr;row<=er;row++){
cout<<a[row][ec] <<", ";
}
ec--;
// step 3 to print the last row;
// print er from ec to sc;
// er--
for(int col=ec;col>=sc;col--){
cout<<a[er][col]<<", ";
}
er--;
// step 4 to print first row reverse;
// print sc from er to sr;
// sc++;
for(int row=er;row>=sr;row--){
cout<<a[row][sc]<<", ";
}
sc++;
}
cout<<"END";
}
int main(){
int m,n;
cin>>n>>m;
int a[10][10];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
spiralPrint(a,n,m);
return 0;
}