n, b = (int(i) for i in input().split())  
l = [input() for i in range(n)] 
z = [-1,0,1]

for i in range(n):
  for ii in range(b):
    if l[i][ii] == "#":
      print("#",end="")
    else:
      print(sum([l[x+i][xx+ii] == "#" for x in z for xx in z if 0 <= x+i < n and 0 <= xx+ii < b]),end="")
  print("")