h, w = map(int, input().split())
matrix = [list(input()) for _ in range(h)]


def get_or_period(l, passed_x, passed_y):
    if passed_x in [-1, w]:
        return '.'
    if passed_y in [-1, h]:
        return '.'
    return l[passed_y][passed_x]


convertedMatrix = []

for y, row in enumerate(matrix):
    convertedMatrix.append([])
    for x, cell in enumerate(row):
        convertedCell = 0
        if matrix[y][x] == "#":
            convertedCell = "#"
            convertedMatrix[y].append(convertedCell)
            continue
        if x == 0 and y == 3:
            print("a")
        for exam_x in [-1, 0, 1]:
            for exam_y in [-1, 0, 1]:
                if get_or_period(matrix, x + exam_x, y + exam_y) == "#":
                    convertedCell += 1
        convertedMatrix[y].append(convertedCell)

for row in convertedMatrix:
    print("".join(map(str, row)))
