h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

import itertools

for i in range(h):
  ans=""
  for j in range(w):
    if s[i][j]=="#":
      ans+="#"
      continue
    temp=0
    for dx,dy in itertools.product([-1,0,1],repeat=2):
      if i+dx<0 or i+dx>=h:
        continue
      if j+dy<0 or j+dy>=w:
        continue
      if s[i+dx][j+dy]=="#":
        temp+=1
    ans+=str(temp)
  print(ans)