H,W = map(int, input().split())
S = [list(input()) for _ in range(H)] #データ形式はS[i][j]

eight = [[-1,-1],[0,-1],[1,-1], # 周囲8マスの定義
         [-1,0],[1,0],
         [-1,1],[0,1],[1,1]]

for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      for e in eight:
        target = S[i+e[0]][j+e[1]]
        if target and target != '#':
          if target == '.' :
            S[i+e[0]][j+e[1]] = 1
          else :
            S[i+e[0]][j+e[1]] += 1

for i in range(H):
  for j in range(W):
    print(S[i][j], end='')
  print('')