H, W = map(int, input().split())
grid = [list('.'+input()+'.') for i in range(H)]
grid.insert(0, list('.' * (W + 2)))
grid.append(list('.' * (W + 2)))
ans = []

for i in range(1, H + 1):
  for j in range(1, W + 1):
    if grid[i][j] == '#':
      ans.append('#')
    else:
      ans.append(str((grid[i-1][j-1:j+2]+grid[i][j-1:j+2]+grid[i+1][j-1:j+2]).count('#')))

  ans.append('\n')
print(''.join(ans))
      
