h,w=map(int,input().split())
li=[input() for i in range(h)]
ans=[[0]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    if li[i][j]=='#':
      ans[i][j]='#'
      for k in range(-1,2):
        for l in range(-1,2):
          if 0<=i+k<h and 0<=j+l<w:
            if ans[i+k][j+l]!='#':
              ans[i+k][j+l]+=1
anss=[map(str,ans[i]) for i in range(h)]
for i in range(h):
  print(''.join(anss[i]))