import itertools
H,W = map(int, input().strip().split(' '))

S = [list('.'*(W+2))]
S += [list('.'+input().strip()+'.') for _ in range(H)]
S.append(list('.'*(W+2)))

for x,y in itertools.product(range(1,W+1), range(1,H+1)):
  if S[y][x] == '#': continue
  S[y][x] = sum([S[y+dy][x+dx] == '#' for dx,dy in itertools.product([-1,0,1], repeat=2)])

for y in range(1,H+1):
  print(*S[y][1:-1], sep='')