H,W=map(int,input().split())
 
S=[input() for i in range(H)]
R=['' for i in range(H)]

for i in range(H):
  for j in range(W):
    sum=0
    if i!=0:
      sum+=S[i-1][max(0,j-1):min(W,j+2)].count('#')
    sum+=S[i][max(0,j-1):min(W,j+2)].count('#')
    if i!=H-1:
      sum+=S[i+1][max(0,j-1):min(W,j+2)].count('#') 
    if S[i][j]=='.':
      R[i]+=str(sum)
    else:      
      R[i]+='#'
    
print(*R,sep='\n')