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