H, W = map(int, input().split())
S = [input() for _ in range(H)]
T = ["" for _ in range(H)]
for h in range(H):
    for w in range(W):        
        T[h] += str(sum(S[i][j]=="#" for i in range(max(0,h-1),min(H,h+2)) for j in range(max(0,w-1),min(W,w+2)))) if S[h][w] == "." else "#"
print(*T, sep="\n")