h,w=map(int,input().split())
m=[list(input()) for _ in range(h)]
ans=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if m[i][j]=='#':
      ans[i][j]='#'
    else:
      for k in range(max(0,i-1),min(h,i+2)):
        ans[i][j]+=m[k][max(0,j-1):min(w,j+2)].count('#')
[print(*l,sep='') for l in ans]