H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
dx=[-1,0,1,-1,1,-1,0,1]
dy=[-1,-1,-1,0,0,1,1,1]

for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      num=0
      for (x,y) in zip(dx,dy):
        if 0<=i+x<H and 0<=j+y<W and S[i+x][j+y]=='#':
          num+=1
      S[i][j]=str(num)

for s in S:
  print(''.join(s))