#include <bits×dc++.h>
using namespace std;
int m,n;
int g[105][105], a = 1, b = 0, d, k = 1; //k为所填的数,d控制转向,a为“行”,b为“列”,要从g[1][1]开始,所以a=1,b=0
int dx[4] = {0, 1, 0, -1}; //转向方向为右下左上
int dy[4] = {1, 0, -1, 0}; //上为(-1,0)下为(1,0)左为(0,-1)右为(0,1)
int main() {
cin >> m >> n;//m行n列
for (int i = 1; i <= m * n; i++) { //共有m*n个数
if ((d == 0 && b == n) || (d == 1 && a == m) || (d == 2 && b <= 1) || (g[a + dx[d]][b + dy[d]] != 0))
//b==n时到达右上角要转向,d+1向下转
//a==m时到达右下角要转向,d+11向左转
//b<=1时到达左下角要转向,d+1向上转
//g[a+dx[d]][b+dy[d]]!=0表示该位置无数字,若=0则代表碰到了数字该转向了,d+=1
{
d++;//转向
if (d == 4) {
d = 0;
}
}
a += dx[d];//a为行
b += dy[d];//b为列
g[a][b] = k; //往此蛇形矩阵中填充数字
k++;
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
cout << g[i][j] <<" ";
}
cout << endl;//输出该蛇形矩阵,记得换行
}
return 0;
}