h, w = [int(i) for i in input().split()]
s = ["."*(w+2)]
for hi in range(h):
  s.append("." + input() + ".")
s.append("."*(w+2))
ans = [""] * h
for hi in range(1,h+1):
  for wi in range(1,w+1):
    if s[hi][wi] == ".":
      ans[hi-1] += str((s[hi-1][wi-1:wi+2]+s[hi][wi-1]+s[hi][wi+1]+s[hi+1][wi-1:wi+2]).count("#"))
    else:
      ans[hi-1] += "#"
for hi in range(h):
  print(ans[hi])