H,W = map(int,input().split())
src = [input() for i in range(H)]
ans = []
for row in src:
    ans.append(list(row))
dxy=[(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
for i in range(H):
    for j in range(W):
        c=0
        if src[i][j]=="#": continue
        for dx,dy in dxy:
            if j+dx<0 or j+dx>W-1 or i+dy<0 or i+dy>H-1: continue
            if src[j+dx][i+dy]=="#":
                c+=1
        ans[i][j]=c
for row in ans:
    print("".join(list(map(str,row))))