h,w=map(int,input().split())
s=["." + input() + "." for _ in range(h)]
s.insert(0,"."*(w+2))
s.append("."*(w+2))
ans=""
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]==".":
            ans+=str((sum([s[i-1][j-1]=="#",s[i-1][j]=="#",s[i-1][j+1]=="#",s[i][j-1]=="#",s[i][j+1]=="#",s[i+1][j-1]=="#",s[i+1][j]=="#",s[i+1][j+1]=="#"])))
        else:
            ans+="#"
    print(ans)
    ans=""
