def check(b, i, j, x, y):
 if i < 0 or j < 0 or i == x or j == y:
  return 0
 if b[i][j] == "#":
  return 1
 return 0

bounds = raw_input().split(" ")
x = int(bounds[0])
y = int(bounds[1])
board = [None] * x
for i in range(0, x):
 k = raw_input()
 board[i] = [None] * y
 for j in range(0, y):
  board[i][j] = k[j]

for i in range(0, x):
 for j in range(0, y):
  if board[i][j] == ".":
   p = 0
   p += check(board, i-1, j-1, x, y)
   p += check(board, i-1, j  , x, y)
   p += check(board, i-1, j+1, x, y)
   p += check(board, i  , j-1, x, y)
   p += check(board, i  , j+1, x, y)
   p += check(board, i+1, j-1, x, y)
   p += check(board, i+1, j  , x, y)
   p += check(board, i+1, j+1, x, y)
   board[i][j] = p
 z = ""
 for j in range(0, y):
  z += str(board[i][j])
 print(z)
