import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); inf=10**18 LI = lambda : list(map(int, input().split())) def dlist(*l, fill=0): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] sys.setrecursionlimit(3*10**5+10) def cycle(rns, ds): """出次数0の頂点を削除しつづける DAGならTPS順序も求まる rns: 逆辺の隣接リスト ds: もとのグラフにおける出次数 返り値 vs: 除かれた頂点 done: 除いたフラグ doneがすべて1でない場合、サイクルが存在する (サイクルに到達できる頂点のみdone==0となる) """ from collections import deque q = deque() n = len(rns) done = [False] * n for u in range(n): if ds[u]==0: q.append(u) done[u] = True vs = [] while q: u = q.popleft() vs.append(u) for v in rns[u]: if done[v]: # これがないとdsが不当に減ってバグになる continue ds[v] -= 1 if ds[v]==0: done[v] = True q.append(v) return vs,done h,w = list(map(int, input().split())) rs = LI() cs = LI() def main(h,w,rs,cs): vs = [[0]*w for _ in range(h)] for i in range(h): vs[i][rs[i]-1] = 1 for i in range(w): vs[cs[i]-1][i] = 1 N = h*w # ns = [[] for _ in range(N)] rns = [[] for _ in range(N)] ds = [0]*N for i in range(h): v = rs[i]-1 uu = w*i + v for j in range(v): if vs[i][j]: vv = w*i + j # ns[vv].append(uu) rns[uu].append(vv) ds[vv] += 1 for j in range(v+1,w): if vs[i][j]: vv = w*i + j # ns[vv].append(uu) rns[uu].append(vv) ds[vv] += 1 for j in range(w): v = cs[j]-1 uu = w*v + j for i in range(v): if vs[i][j]: vv = w*i + j # ns[vv].append(uu) rns[uu].append(vv) ds[vv] += 1 for i in range(v+1,h): if vs[i][j]: vv = w*i + j # ns[vv].append(uu) rns[uu].append(vv) ds[vv] += 1 vals, done = cycle(rns, ds) assert all(done) ans = [[0]*w for _ in range(h)] val = 10**9 for i in range(h): for j in range(w): ans[i][j] = (1+i+j) for ind in vals: i,j = divmod(ind, w) if vs[i][j]==0: continue ans[i][j] = val val -= 1 return ans ans = main(h,w,rs,cs) for item in ans: write(" ".join(map(str, item)))