H,W=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) A.sort() B.sort(reverse=True) degree=[0]*H*W edges=[] for h in range(H): for w in range(A[h]-1): edges.append((h*W+w,h*W+w+1)) for w in range(A[h],W-1): edges.append((h*W+w+1,h*W+w)) for w in range(W): for h in range(B[w]-1): edges.append((h*W+w,(h+1)*W+w)) for h in range(B[w],H-1): edges.append(((h+1)*W+w,h*W+w)) graph=[[] for x in range(H*W)] for x,y in edges: graph[x].append(y) degree[y]+=1 queue=[x for x in range(H*W) if degree[x]==0] ans_lst=[[None]*W for h in range(H)] n=1 while queue: x=queue.pop() h,w=divmod(x,W) ans_lst[h][w]=n n+=1 for y in graph[x]: degree[y]-=1 if degree[y]==0: queue.append(y) for h in range(H): print(*ans_lst[h])