import sys


def check(newLine, index, row, col):
    count = 0
    # 左と右
    if index % col != 0:
        if newLine[index - 1] == "#":
            count += 1
    if index % col != col - 1:
        if newLine[index + 1] == "#":
            count += 1
    # 上と下
    if index > col:
        if newLine[index - col] == "#":
            count += 1
    if index < col * (row - 1):
        if newLine[index + col] == "#":
            count += 1
    # 上の左と右
    if 0 <= index - col - 1 < len(newLine) and index - col % col != 0:
        if newLine[index - col - 1] == "#":
            count += 1
    if 0 <= index - col + 1 < len(newLine) and index - col % col != col - 1:
        if newLine[index - col + 1] == "#":
            count += 1
    # 下の左と右
    if 0 <= index + col - 1 < len(newLine) and index + col % col != 0:
        if newLine[index + col - 1] == "#":
            count += 1
    if 0 <= index + col + 1 < len(newLine) and index + col % col != col - 1:
        if newLine[index + col + 1] == "#":
            count += 1

    newLine[index] = str(count)
    return newLine


def main(lines):
    row = int(lines[0][0])
    col = int(lines[0][2])

    newLine = list("".join(lines[1:]))
    for index, value in enumerate(newLine):
        if value == ".":
            newLine = check(newLine, index, row, col)
    for i in range(0, len(newLine), col):
        print("".join(newLine[i:i + col]))


if __name__ == '__main__':
    # lines = ['6 6', '#####.', '#.#.##', '####.#', '.#..#.', '#.##..', '#.#...']
    # lines = ['6 5', '.##.#', '.####', '..##.', '..#..', '.....', '.....']
    # lines = ['3 5', '.....', '.#.#.', '.....']

    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)
