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

for i in range(H):
    A = ""
    for j in range(W):
        if S[i][j] == "#":
            A += "#"
        else:
            C = 0
            for SS in S[max(0,i-1):min(H,i+2)]:
                C += SS[max(0,j-1):min(W,j+2)].count("#")
            A += str(C)
    print(A)