h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j]==".":
      x=[(i+1,j+1),(i,j+1),(i-1,j+1),(i+1,j),(i-1,j),(i+1,j-1),(i,j-1),(i-1,j-1)]
      x = [(p,q) for p,q in x if min(p,q)>=0 and p<h and q<w]
      y=0
      for p,q in x:
        if s[p][q]=="#":
          y+=1
      s[i][j]=str(y)
for i in range(h):
  print("".join(s[i]))