from collections import deque H, W = map(int, input().split()) R = list(map(int, input().split())) C = list(map(int, input().split())) def F(i, j): return i * W + j def parse(id): return divmod(id, W) deg = [0] * (H * W) G = [[] for _ in range(H * W)] for i, r in enumerate(R): for j in range(r-1): G[F(i, j+1)].append(F(i, j)) deg[F(i, j)] += 1 for j in range(r-1, W-1): G[F(i, j)].append(F(i, j+1)) deg[F(i, j+1)] += 1 for j, c in enumerate(C): for i in range(c-1): G[F(i+1, j)].append(F(i, j)) deg[F(i, j)] += 1 for i in range(c-1, H-1): G[F(i, j)].append(F(i+1, j)) deg[F(i+1, j)] += 1 def prin(): for i in range(H): for j in range(W): print(deg[i*W+j], end=" ") print() print() val = H * W + 10 ans = [[-1] * W for _ in range(H)] cand = list(range(H * W)) que = deque() for i, d in enumerate(deg): if d == 0: que.append(i) while que or cand: found = False if que: while True: s = que.popleft() x, y = parse(s) if ans[x][y] == -1: found = True break else: cand.sort(key=lambda x: (-deg[x])) while cand: s = cand.pop() x, y = parse(s) if ans[x][y] == -1: found = True break if not found: break ans[x][y] = val val -= 1 for t in G[s]: deg[t] -= 1 if deg[t] == 0: que.append(t) for a in ans: print(*a)