#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np H, W = map(int, readline().split()) A = np.array(readline().split(), np.int64) B = np.array(readline().split(), np.int64) A.sort() B.sort() L = 1 R = H * W C = np.zeros((H, W), np.int64) D = C[:] while True: H, W = D.shape if not H: break if not W: break if B[0] >= 2: D[0] = L + np.arange(W) L += W n = A[0] D[0][n-1:] = D[0][n-1:][::-1] A = A[1:] B -= 1 D = D[1:] continue if A[0] >= 2: A, B = B, A D = D.T continue assert A[0] == 1 n = np.count_nonzero(B <= 1) D[0][n:] = (L + np.arange(W - n))[::-1] D[0][:n] = R - np.arange(n) L += W - n R -= n A = A[1:] B[n:] -= 1 D = D[1:] continue print('\n'.join(' '.join(row) for row in C.astype(str)))