h, w = map(int, input().split())
S = [list(input()) for i in range(h)]

for i in range(h):
  for j in range(w):
    if S[i][j]=='#':
      continue
    cnt = 0
    for x in [-1, 0, 1]:
      for y in [-1, 0, 1]:
        if not 0 <= i+y < h or not 0 <= j+x < w:
          continue
        if S[i+y][j+x]=='#':
          cnt += 1
    S[i][j] = str(cnt)
for s in S:
  print(''.join(s))