h,w=map(int,input().split())
l=[input() for i in range(h)]
cl=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if l[i][j]=="#":
            for a in {max(0,i-1),i,min(h-1,i+1)}:
                for b in {max(0,j-1),j,min(w-1,j+1)}:
                    cl[a][b]+=1
cl=[[str(cl[i][j]) if l[i][j]!="#" else "#" for j in range(w)] for i in range(h)]
for i in range(h):
    print("".join(cl[i]))