H,W=map(int,input().split())
S=[input() for _ in range(H)]
for i in range(H):
  T=''
  for j in range(W):
    if S[i][j] == '#':
      T+='#'
    else:
      T+=str(sum([x[max(0,j-1):min(j+2,W)].count('#') for x in S[max(0,i-1):min(i+2,H)]]))
    
  print(T)   
