import java.io.*; import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNextInt()){ int m = sc.nextInt(); int n = sc.nextInt(); if(m == -1 && n == -1){ break; } int[][] dp = new int[m][n]; for(int i = 0; i < m; ++i){ for(int j = 0; j < n; ++j){ dp[i][j] = sc.nextInt(); } } fun(dp); } } public static void fun(int[][] dp){ StringBuilder sb = new StringBuilder(); int m = dp.length; int n = dp[0].length; int r1 = 0, r2 = m - 1, c1 = 0, c2 = n - 1; while(r1 <= r2 && c1 <= c2){ for(int i = c1; i <= c2; ++i){ sb.append(dp[r1][i]+","); } for(int i = r1 + 1; i <= r2; ++i){ sb.append(dp[i][c2]+","); } if(r1 != r2){ for(int i = c2 - 1; i >= c1; --i){ sb.append(dp[r2][i]+","); } } if(c1 != c2){ for(int i = r2 - 1; i >= r1 + 1; --i){ sb.append(dp[i][c1]+","); } } r1++; r2--; c1++; c2--; } System.out.println(sb.deleteCharAt(sb.length() - 1).toString()); } }