H, W = map(int, input().split())
import numpy as np
x = np.zeros((H,W))
for i in range(H):
  x[i,] = map(int, input().split())

temp_list = []
for i in range(H):
  for j in range(W):
    if x[i,j] == "#":
      continue
    elif i == 0 and j == 0:
      temp_list = [x[i,j+1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0 and j == W:
      temp_list = [x[i,j-1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H and j == 0:
      temp_list = [x[i-1,j:j+1],x[i,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H and j == W:
      temp_list = [x[i-1,j-1:j],x[i,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0:
      temp_list = [x[i,j-1],x[i,j+1],x[i+1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H:
      temp_list = [x[i,j-1],x[i,j+1],x[i-1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == 0:
      temp_list = [x[i-1,j:j+1],x[i,j+1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == W:
      temp_list = [x[i-1,j-1:j],x[i,j-1],x[i+1,j-1:j]]
      counts = temp_list.count("#")
      x[i,j] = counts
    else:
      temp_list = [x[i-1,j-1:J+1],x[i,j-1],x[i,j+1],x[i+1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
      
for i in range(H):
  print(x[i,])
 