h, w = map(int, input().split())
c = list(map(int, input.split()))
d = list(map(int, input.split()))
field = [list(map(int, input().split()) for _ in range(h))]
for i in range(h):
    for j in range(w):
        field[i][j]: