H,W=map(int,input().split());S=[input()for _ in range(H)];T=[""]*H
for i,l in enumerate(S):
 for j,c in enumerate(l):
  T[i]+=str(sum(S[i+p][j+q]=="#"for p in[-1,0,1]for q in[-1,0,1]if(0<=i+p<H)&(0<=j+q<W)))if c=="."else c
print("\n".join(T))