W,H=map(int,input().split())
arr=[[0 for i in range(H)] for j in range(W)]
ans=[[0 for i in range(H)] for j in range(W)]

for i in range(W):
    gyou=input()
    for j in range(H):
        arr[i][j]=gyou[j:j+1]


for i in range(W):
    for j in range(H):
        if arr[i][j]=="#":
            ans[i][j]="#"
        else:    
            for k in range(-1,2):
                for l in range(-1,2):
                    try:
                        if arr[i+k][l+j]=="#":
                            ans[i][j]+=1
                    except:
                        pass
for i in range(W):
    ans1=map(str,ans[i])
    ans2="".join(ans1)
    
    print(ans2)