h,w=map(int,input().split())
s=[input() for _ in range(h)]
 
for i in range(h):
    ans=""
    for j in range(w):
        if(s[i][j]=="#"):
            ans+="#"
        else:
            tmp=0
            for k in s[max(0, i-1):min(h, i+2)]:
                tmp+=k[max(0, j-1):min(w, j+2)].count("#")
                
            ans+=str(tmp)
    print(ans)