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

for i in range(1, H+1):
  for j in range(1, W+1):
    if fields[i][j] == '#':
      continue
    else:
      mine_cnt = 0
      if fields[i][j-1] == '#':
        mine_cnt += 1
      if fields[i][j+1] == '#':
        mine_cnt += 1
      if fields[i-1][j] == '#':
        mine_cnt += 1
      if fields[i+1][j] == '#':
        mine_cnt += 1
      fields[i][j] = mine_cnt
for i in range(1 , H):
  row = ''.join(fields[i][1:W+1])
  print(row)

  