H,W= map(int,input().split())
mine = [list(input()) for i in range(H)]

def count(ch):
  return 1 if ch == '#' else 0

for i in range(H):
  for j in range(W):
    num = 0
    if mine[i][j] == '#':
      continue
    else:
      for k in range(-1,2):
        for l in range(-1,2):
          num += (1 if mine[i+k][j+l]=='#' else 0) 
      mine[i][j] = num
      
for i in range(1,H+1):
  for j in range(1,W+1):
    print(mine[i][j],end='')
  print()

