h,w=map(int,input().split())
s=[input() for i in range(h)]
a=[[0]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    t=0
    if i==0:
      if j==0:
        if s[i][j+1]=="#":t+=1
        if s[i+1][j+1]=="#":t+=1
        if s[i+1][j]=="#":t+=1
      elif 0<j<w-1:
        if s[i][j+1]=="#":t+=1
        if s[i+1][j+1]=="#":t+=1
        if s[i+1][j]=="#":t+=1
        if s[i+1][j-1]=="#":t+=1
        if s[i][j-1]=="#":t+=1        
      elif j==w-1:
        if s[i+1][j]=="#":t+=1
        if s[i+1][j-1]=="#":t+=1
        if s[i][j-1]=="#":t+=1 
    elif 0<i<h-1:
      if j==0:
        if s[i-1][j]=="#":t+=1
        if s[i-1][j+1]=="#":t+=1
        if s[i][j+1]=="#":t+=1
        if s[i+1][j+1]=="#":t+=1
        if s[i+1][j]=="#":t+=1
      elif 0<j<w-1:
        if s[i][j+1]=="#":t+=1
        if s[i+1][j+1]=="#":t+=1
        if s[i+1][j]=="#":t+=1
        if s[i+1][j-1]=="#":t+=1
        if s[i][j-1]=="#":t+=1
        if s[i-1][j-1]=="#":t+=1
        if s[i-1][j]=="#":t+=1
        if s[i-1][j+1]=="#":t+=1
      elif j==w-1:
        if s[i+1][j]=="#":t+=1
        if s[i+1][j-1]=="#":t+=1
        if s[i][j-1]=="#":t+=1
        if s[i-1][j-1]=="#":t+=1
        if s[i-1][j]=="#":t+=1      
    elif i==h-1:
      if j==0:
        if s[i][j+1]=="#":t+=1
        if s[i-1][j+1]=="#":t+=1
        if s[i-1][j]=="#":t+=1
      elif 0<j<w-1:
        if s[i][j+1]=="#":t+=1
        if s[i-1][j+1]=="#":t+=1
        if s[i-1][j]=="#":t+=1
        if s[i-1][j-1]=="#":t+=1
        if s[i][j-1]=="#":t+=1        
      elif j==w-1:
        if s[i-1][j]=="#":t+=1
        if s[i-1][j-1]=="#":t+=1
        if s[i][j-1]=="#":t+=1
    if s[i][j]=="#":
      a[i][j]="#"
    else:
       a[i][j]=t
for aa in a:
  tt=""
  for aaa in aa:
    tt+=str(aaa)
  print(tt)