h,w=map(int,input().split())
s=[list("."+input()+".") for _ in range(h)]
s= [["."]*(w+2)] + s + [["."]*(w+2)] 
for i in range(1,h+1):
    l=[]
    for k in range(1,w+1):
        if s[i][k]=="#":
            p="#"
        else:
            p=0
            p+=s[i-1][k-1:k+2].count("#")
            p+=s[i][k-1:k+2].count("#")
            p+=s[i+1][k-1:k+2].count("#")
        l.append(str(p))
    print("".join(l))
