H,W=map(int,input().split())
S=[input() for i in range(H)]
for h in range(H):
        print("".join([("#" if S[h][w] == "#" else str(sum([s[max(0,w-1):min(W,w+2)].count("#") for s in S[max(0,h-1):min(H,h+2)]]))) for w in range(W)]))