H,W=map(int,input().split())
l=[""]*W
ll=[["" for i in range(W)] for j in range(H)] 
for i in range(H):
  l[i]=[i for i in input()] 
for h in range(H):
  for w in range(W):
    if l[h][w]=="#":
      ll[h][w]="#"
    else:  
      cnt=0
      for hh in [-1,0,1]:
        for ww in [-1,0,1]:
          if 0<=h+hh<H and 0<=w+ww<W:
            if l[h+hh][w+ww]=="#":
              cnt+=1
      ll[h][w]=str(cnt)   
for i in range(H):
  print("".join(ll[i]))