#!/usr/bin/python

from sys import stdin

def count(S, i, j):
  c = 0
  for y in range(i - 1, i + 2):
    for x in range(j - 1, j + 2):
      if 0 <= y < len(S) and 0 <= x < len(S[y]) and S[y][x] == '#':
        c += 1
  return str(c)

def solve(S):
  return [[count(S, i, j) if S[i][j] == '.' else '#'
          for j in range(len(S[i]))] for i in range(len(S))]

H, W = [int(w) for w in stdin.readline().split()]
S = []
for i in range(H):
  S.append(stdin.readline().strip())
R = solve(S)
R = '\n'.join([''.join(r) for r in R])
print(R)
