H, W = map(int, raw_input().split())
s = []
for i in xrange(H):
  s.append(list(raw_input()))

for y in xrange(H):
  for x in xrange(W):
    if s[y][x] == '#':
      continue
    count = 0
    for dy in [-1, 0, 1]:
      for dx in [-1, 0, 1]:
        ny = y + dy
        nx = x + dx
        if 0 <= ny < H and 0 <= nx < W:
          if s[ny][nx] == '#':
            count += 1
    s[y][x] = str(count)

for i in xrange(H):
  print ''.join(s[i])