import sys

def main():
    H, W = map(int, raw_input().split(" "))
    matrix = []
    for _ in range(H):
        matrix.append(list(raw_input()))

    for i in range(H):
        for j in range(W):
            if matrix[i][j] == "#":
                continue

            num_bombs = 0
            if i - 1 >= 0 and j - 1 >= 0 and matrix[i - 1][j - 1] == "#":
                num_bombs += 1
            if j - 1 >= 0 and matrix[i][j - 1] == "#":
                num_bombs += 1
            if i - 1 >= 0 and matrix[i - 1][j] == "#":
                num_bombs += 1
            if i + 1 < H and j + 1 < W and matrix[i + 1][j + 1] == "#":
                num_bombs += 1
            if j + 1 < W and matrix[i][j + 1] == "#":
                num_bombs += 1
            if i + 1 < H and matrix[i + 1][j] == "#":
                num_bombs += 1
            if i - 1 >= 0 and j + 1 < W and matrix[i - 1][j + 1] == "#":
                num_bombs += 1
            if i + 1 < H and j - 1 >= 0 and matrix[i + 1][j - 1] == "#":
                num_bombs += 1

            matrix[i][j] = str(num_bombs)

    for i in range(H):
        for j in range(W):
            sys.stdout.write(matrix[i][j])
        print ""

if __name__ == '__main__':
    main()
