H, W = map(int, input().split())

M = [["."*W]]
M = [[".", *input(), "."] for i in range(H)]
M.insert(0,[*("."*(W+2))])
M.append([*("."*(W+2))])

cnt = 0
Ans = []
for i in range(1, H+1):
    for j in range(1, W+1):
        if M[i][j] == ".":
            for k in range(-1, 2):
                if M[i+k][j-1] == "#":
                    cnt += 1
                if M[i+k][j] == "#":
                    cnt += 1
                if M[i+k][j+1] == "#":
                    cnt += 1
            print(cnt, end = "")
            cnt = 0
        else:
            print("#", end = "")
    print()
