#include
using namespace std;
void anti_clock_spiral(int arr[][1000],int m,int n){
int sr=0;
int sc=0;
int er=m-1;
int ec=n-1;
while(sr<=er && sc<=ec){
for(int i=sr;i<=er;i++){
cout<<arr[i][sc]<<", ";
}
sc++;
for(int j=sc;j<=ec;j++){
cout<<arr[er][j]<<", ";
}
er--;
if(ec>sc){
for(int i=er;i>=sr;i--){
cout<<arr[i][ec]<<", ";
}
ec--;
}
if(sr<er){
for(int j=ec;j>=sc;j--){
cout<<arr[sr][j]<<", ";
}
sr++;
}
}
}
int main() {
int m,n;
cin>>m>>n;
int arr[m][1000]={0};
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
anti_clock_spiral(arr,m,n);
cout<<" END";
return 0;
}