h,w = map(int,input().split())
ss = [input() for _ in [0]*h]
for i in range(h):
  ans = ''
  for j in range(w):
    if ss[i][j] == '#':
      ans += '#'
      continue
    n = 0
    if i > 0:
      n += ss[i-1][max(0,j-1):j+2].count('#')
    n += ss[i][max(0,j-1):j+2].count('#')
    if i != h-1:
      n += ss[i+1][max(0,j-1):j+2].count('#')
    ans += str(n)
  print(ans)