H, W = map(int, input().split())
S = [input() for i in range(H)]
C = [[0 for i in range(W)] for j in range(H)]
 
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]
 
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      for k in range(8):
        if 0 <= j + dx[k] < W and 0 <= i + dy[k] < H:
          if S[i + dy[k]][j + dx[k]] == '#':
            C[i][j] += 1
          else:
            pass
        else:
          pass
    else:
      C[i][j] = '#'
 
for i in range(H):
  for j in range(W):
    print(C[i][j], end = '')