H,W = map(int, input().split())
L = [[x if x=='#' else 0 for x in input()] for _ in range(H)]

for i in range(H):
  l = L[i]
  l_before=None
  l_after=None
  if i>0:
    l_before=L[i-1]
  if i<H-1:
    l_after=L[i+1]
    
  for j in range(W):
    if l[j] != '#':
      try:
        if l_before[j-1]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l_before[j]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l_before[j+1]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l[j-1]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l[j+1]=='#':
          l[j]+=1
      except:
        pass
      
      try:
        if l_after[j-1]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l_after[j]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l_after[j+1]=='#':
          l[j]+=1
      except:
        pass


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

      

  