#include
using namespace std;
int main() {
int n , m, row, col;
cin>>n>>m;
int a[10][10];
for(row=0;row<n;row++)
{
for(col=0;col<m;col++)
cin>>a[row][col];
}
int sc=0;
int ec=m-1;
int sr=0;
int er=n-1;
while(sr<=er and sc<=ec){
for(col=sc;col<=ec;col++){
cout<<a[sr][col]<<", ";}
sr++;
for(row=sr;row<=er;row++){
cout<<a[row][ec]<<", ";}
ec--;
for(col=ec;col>=sc;col--){
cout<<a[er][col]<<", ";}
er--;
for(row=er;row>=sr;row--){
cout<<a[sc][row]<<", ";}
sc++;
}
cout<<"END";
return 0; }