H, W = map(int, input().split())
list = []
for i in range(H):
  s = input()
  list.append(s)
ans = [[0] * W for i in range(H)]  

for i in range(H):
  for j in range(W):
    if list[i][j] == '#':
      try:
        ans[i][j] = ''
        ans[i][j] = '#'
      except:
        pass
      try:
        ans[i-1][j-1] += 1
      except:
        pass
      try:
        ans[i-1][j] += 1
      except:
        pass
      try:
        ans[i-1][j+1] += 1
      except:
        pass
      try:
        ans[i][j-1] += 1
      except:
        pass
      try:
        ans[i][j+1] += 1
      except:
        pass
      try:
        ans[i+1][j-1] += 1
      except:
        pass
      try:
        ans[i+1][j] += 1
      except:
        pass
      try:
        ans[i+1][j+1] += 1
      except:
        pass

for i in range(H):
  line = ''
  for j in range(W):
    line += str(ans[i][j])
  print(line)