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

mine = [[0 for _ in range(W)] for _ in range(H)]
for j in range(H):
  for i in range(W):
    if S[j + 1][i + 1] == '#':
      mine[j][i] = '#'
    else:
      mine[j][i] = sum([s[i:i + 3].count('#') for s in S[j:j + 3]])
      
for m in mine:
  print(''.join([str(i) for i in m]))
