H, W = map(int, input().split())
S = [list(map(int, input().split())) for i in range(H)]
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

for i in range(H):
  for j in range(W):
    if s[i][j] == '.':
      cnt = 0
      for n in range(8):
        ni = i + dx[n]
        nj = j + dy[n]
        if ni < 0 or ni >= H:
          continue
        if nj < 0 or nj >= W:
          continue
        if s[ni][nj] == '#':
          cnt += 1
      S[i][j] = str(cnt)

print(S)
    
