h,w=map(int,input().split())
e=["*" for i in range(w+2)]
s=[e]
for i in range(h):
  s.append(["*"]+list(input())+["*"])
s.append(e)

for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]==".":
      s[i][j]=str(sum(s[k][j-1:j+2].count("#") for k in range(i-1,i+2)))
  print("".join(s[i][1:w+1]))
