#include <stdio.h>
#include <stdlib.h>

//必要があれば変数などを追加してもOKです

int main(){
    int i,j,k;
    int a,b;
    int **mat;
    scanf("%d %d",&a,&b);

	//ここで2次元配列の動的確保をする
    if((mat = (int **)malloc(sizeof(int)*a*b))==NULL){printf("ERROR: Couldn't allocate memmory.\n");return 1;}
    for(i=0; i<a; i++){
        if((mat[i] = (int *)malloc(sizeof(int)*b))==NULL){printf("ERROR: Couldn't allocate memmory.\n");return 1;}
    }
    //printf("SUCCESS to allocate memory: %p\n", mat);
	//ここで2次元配列に数値を代入する
    k = 1; // 代入していく数
    for(i=0; i<a; i++){
        for(j=0; j<b; j++){
            //printf("SUCCESS to inits\n"); return 0;
            mat[i][j] = k;
            //printf("mat(%d,%d)=%d\n", j, i, k);
            k++;
        }
    }

    //以下の部分は表示の部分です
    //いじらなくてOK
    for(i=0;i<a;i++){
        for(j=0;j<b;j++){
            printf("%d ",mat[i][j]);
        }
        printf("\n");
    }

    //さて，最後に忘れずにすることと言えば？
    for(i=0; i<a; i++){
        free(mat[i]);
    }
    free(mat);

    return 0;
}
