H,W = map(int, input().split())
print(H,W)
S = [input() for i in range(H)]

count = []
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    if 0 <= i+x < H and 0 <= j+y < W:
                        if S[i+x][j+y] == "#":
                            cnt += 1
            print(cnt,end="")
        else:
            print("#",end="")
    print()






