a=input().split()
H=int(a[0])
W=int(a[1])
A=[]
B=[]

for i in range(H):
  a=input()
  a=list(a)
  if(i!=H-1):
   a.pop()   
  A.append(a)

for i in range(H):
  for j in range(W):
    if(A[i][j]=="."):
     A[i][j]=0

for i in range(H):
  if((i!=0)and(i!=H-1)):
   for j in range(W):
     if((j!=0)and(j!=W-1)):
        if( (A[i-1][j]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i+1][j]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1
        if( (A[i][j-1]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1
        if( (A[i][j+1]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1

for i in range(H):
   for j in range(W): 
      if( (i==0)and(j!=0)and(j!=W-1) ):
        if( (A[i][j-1]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i][j+1]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1
      if( (i==H-1)and(j!=0)and(j!=W-1) ):
        if( (A[i][j-1]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i][j+1]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
      if( (j==0)and(i!=0)and(i!=H-1) ):
        if( (A[i-1][j]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i+1][j]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1
      if( (j==W-1)and(i!=0)and(i!=H-1) ):
        if( (A[i-1][j]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i+1][j]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1
          
      if( (i==0)and(j==0) ):
        if( (A[i+1][j]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i][j+1]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1
      if( (i==0)and(j==W-1) ):
        if( (A[i+1][j]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i][j-1]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1
      if( (i==H-1)and(j==0) ):
        if( (A[i-1][j]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i][j+1]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1
      if( (i==H-1)and(j==W-1) ):
        if( (A[i-1][j]=="#")and(A[i][j]!="#") ):
          A[i][j] +=1
        if( (A[i][j-1]=="#")and(A[i][j]!="#") ): 
          A[i][j] +=1

print(A)