H, W = map(int, input().split())
S = ['.'*(W+2)] + ['.'+input()+'.' for _ in range(H)] + ['.'*(W+2)]

for hi in range(1, H+1):
  ans = ''
  for wi in range(1, W+1):
    if S[hi][wi] == '#':
      ans += '#'
    else:
      now = 0
      for hii in [-1, 0, 1]:
        for wii in [-1, 0, 1]:
          if S[hi+hii][wi+wii] == '#':
            now += 1
      ans += str(now)
  print(ans)