H,W = map(int, raw_input().split())
S = [raw_input() for y in range(H)]
A = [list(s) for s in S]
for y in range(H):
  for x in range(W):
    if S[y][x]!='#':
      c = 0
      for dx in range(-1,2):
        for dy in range(-1,2):
          if (dx,dy)!=(0,0) and 0<=x+dx<W and 0<=y+dy<H and S[y+dy][x+dx]=='#':
            c += 1
      A[y][x] = str(c)
for a in A:
  print ''.join(a)
