h, w = [int(x) for x in input().split()]
grid = [[b for b in input()] for i in range(h)]
result = []
for i in range(h):
    row = ''
    for j in range(w):
        if grid[i][j] == '#':
            row += '#'
        else:
            row += str(sum([area[max(0, j - 1):min(w, j + 2)].count('#')
                            for area in grid[max(0, i - 1):min(h, i + 2)]]))
    result.append(row)
print('\n'.join(result))
