H, W = map(int, input().split())

S = [list(input()) for i in range(H)]

if H >= 3 and W >= 3:
  for i in range(1,H-1):
    for j in range(1,W-1):
      if S[i][j] == '.':
        x = [S[i-1][j-1], S[i-1][j], S[i-1][j+1], S[i][j-1], S[i][j+1],S[i+1][j-1], S[i+1][j],S[i+1][j+1]]
        S[i][j] = x.count('#')
if W >=3 and H >=2:
  for j in range(1,W-1):
    if S[0][j] == '.':
      x = [S[0][j-1], S[0][j+1], S[1][j-1], S[1][j], S[1][j+1]]
      S[0][j] = x.count('#')

    if S[H-1][j] == '.':
      x = [S[H-1][j-1], S[H-1][j+1], S[H-2][j-1], S[H-2][j], S[H-2][j+1]]
      S[H-1][j] = x.count('#')
      
if H >=3 and W >=2:
  for i in range(1, H-1):
    if S[i][0] == '.':
      x =[S[i-1][0],S[i-1][1],  S[i][1], S[i+1][0], S[i+1][1]]
      S[i][0] = x.count('#')
    if S[i][W-1] == '.':
      x =[S[i-1][W-1],S[i-1][W-2],  S[i][W-2], S[i+1][W-1], S[i+1][W-2]]
      S[i][W-1] = x.count('#')
if H >=2 and W >= 2:
  if S[0][0] == '.':
    x = [S[0][1], S[1][0], S[1][1]]
    S[0][0] =x.count('#')
  if S[0][W-1] == '.':
    x = [S[0][W-2], S[1][W-1], S[1][W-2]]
    S[0][W-1] = x.count('#')
  if S[H-1][0] == '.':
    x = [S[H-1][1], S[H-2][0], S[H-2][1]]
    S[H-1][0] = x.count('#')

  if S[H-1][W-1] == '.':
    x = [S[H-1][W-2], S[H-2][W-1], S[H-2][W-2]]
    S[H-1][W-1] = x.count('#')
    
if H == 1 and W >=2:
  if S[0][0] == '.':
    x = [S[0][1]]
    S[0][0] = x.count('#')
  if S[0][W-1] == '.':
    x = [S[0][W-2]]
    S[0][W-1] = x.count('#')
if H >= 2 and W ==1:
  if S[0][0] == '.':
    x =[S[1][0]]
    S[0][0] = s.count('#')
  if S[H-1][0] == '.':
    x = [S[H-2][0]]
    S[H-1][0] = x.count('#')
    
if H == 1 and W == 1:
  if S[0][0] == '.':
    S[0][0] = 0

for i in range(len(S)):
  S[i] = [str(x) for x in S[i]]
  print(''.join(S[i]))
  