h,w=map(int,input().split())
T=["."+input()+"." for i in range(h)]
S="."*(w+2)
T.insert(0,S)
T.append(S)
Ans=["" for i in range(h)]
for i in range(1,h+1):
  for j in range(1,w+1):
    count=0
    if T[i][j]=="#":
      A="#"
    elif T[i][j]==".":
      for m in range(3):
        for n in range(3):
          if T[i-1+m][j-1+n]=="#":
            count+=1
          A=str(count)
    Ans[i-1]+=A
print(*Ans,sep="\n")