H,W = map(int,input().split())
S=[]
for i in range(H):
    S.append(input())
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            S[i] = S[i].replace(".","0",1)
            rec = 0
            for d in [(1,0),(1,1),(0,1),(-1,1),(-1,0),(-1,-1),(0,-1),(1,-1)]:
                nx,ny = i+d[0],j+d[1]
                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "#":
                    rec += 1
            S[i] = S[i].replace("0",str(rec))

for i in range(H):
    print(S[i])