h,w=map(int,input().split())
S= [[j for j in input()] for i in range(h)]
for i in range(h):
  for j in range(w):
    a=0
    if S[i][j]==".":
      for p in range(-1,2):
        for k in range(-1,2):
          if 0<=i+p<h and 0<=j+k<w:
            if S[i+p][j+k]=="#":
              a+=1
      S[i][j]=str(a)

for i in S:
  print("".join(i))
