H,W=map(int,input().split())
S=["."*(W+2)]+["."+input()+"." for i in range(H)]+["."*(W+2)]
for i in range(H):
    for j in range(W):
        c=S[i+1][j+1]
        if c==".":
            c=sum([S[k][j:j+3].count("#") for k in range(i,i+3)])
        print(c,sep="",end="")
    print("")