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)


### FIXED CODE ###

import sys


def check(newLine, index, row, col):
    count = 0

    # 左と右
    if index % col != 0:# 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

    # 上の左と右 0 <= index + col + 1 < len(newLine) and
    if index >= col and index % col != 0: #首行でない かつ　0列でない
        if newLine[index - col - 1] == "#":
            count += 1
    if index >= col and index % col != col - 1: #首行でない かつ　末列でない
        if newLine[index - col + 1] == "#":
            count += 1
    # 下の左と右
    if index < col * (row - 1) and index % col != 0:
        if newLine[index + col - 1] == "#":
            count += 1
    if index < col * (row - 1) and index % col != col - 1:
        if newLine[index + col + 1] == "#":
            count += 1

    newLine[index] = str(count)
    return newLine


def main(row,col,lines):

    newLine = list("".join(lines))
    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', '.....', '.#.#.', '.....']

    row, col = map(int, input().split())
    lines = list(str(input()) for i in range(row))
    #lines = []
    #for l in sys.stdin:
    #    lines.append(l.rstrip('\r\n'))
    main(row,col,lines)