week6lab

# Step 1: read the input
 
parts = input().split()
 
r = int(parts[0])
 
c = int(parts[1])
 
survey = []
 
for i in range(r):
 
    row_parts = input().split()
 
    row = []
 
    for j in range(c):
 
        row.append(int(row_parts[j]))
 
    survey.append(row)
 
# Step 2: write your program here.
 
for i in range(r):
 
    for j in range(c):
 
        if survey[i][j]==1:
 
            survey[i][j]="X"
 
answer=survey[:]
 
for i in range(r):
 
    for j in range(c):
 
        if answer[i][j]=="X":
 
            for a in [-1,0,1]:
 
                for b in [-1,0,1]:
 
                    p,q= i+a,i+b
 
                    if 0<=p<r and 0<=q<c:
 
                        if answer[p][q] != "X":
 
                            answer[p][q] += 1
 
  
 
# Build the map, row by row, in the list of lists called answer.
 
answer = survey
 
# Step 3: print the output
 
for i in range(r):
 
    line = ""
 
    for j in range(c):
 
        if j > 0:
 
            line = line + " "
 
        line = line + str(answer[i][j])
 
    print(line)