H,W=map(int,input().split())
S=["."]*(W+2)
S=[["."]*(W+2)] + [list("."+input()+".") for _ in range(H)] + [["."]*(W+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j] == "#":
            print("#",end="")
        else:
            print((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]).count("#"),end="")
    print()