H,W=map(int,input().split())
M=[input() for x in range(H)]
A=[[0 for x in range(W)]for y in range(H)]
nx=[-1,0,1]
ny=[-1,0,1]

for i in range(H):
  for j in range(W):
    if M[i][j]=='.':
      cnt=0
      for x in nx:
        for y in ny:
          if (0<= i+x <H) and (0<= j+y <W) and M[i+x][j+y]=="#":
            cnt+=1
      A[i][j]=str(cnt)
    else:
      A[i][j]="#"
      
for i in range(H):
  print("".join(A[i]))