def generate_minesweeper_matrix(n, m, matrix):
# Directions array for 8 neighboring cells
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
result = []
for i in range(n):
row = []
for j in range(m):
if matrix[i][j] == "*":
row.append("*")
else:
mine_count = 0
for di, dj in directions:
ni, nj = i + di, j + dj
if 0 <= ni < n and 0 <= nj < m and matrix[ni][nj] == "*":
mine_count += 1
row.append(str(mine_count))
result.append("".join(row))
return result
# Input reading
n, m = map(int, input().split())
matrix = []
for _ in range(n):
matrix.append(input().strip())
# Generate minesweeper matrix
minesweeper_matrix = generate_minesweeper_matrix(n, m, matrix)
# Output the result
for row in minesweeper_matrix:
print(row)