h,w=map(int,input().split())
s=[input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=0
            for x in range(-1,2):
                for y in range(-1,2):
                    if 0<=i+x<h and 0<=j+y<w and s[i+x][j+y]=="#":
                        cnt+=1
            print(cnt,end="")
        else:
            print("#",end="")
    print()