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)

### FIXED CODE ###

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

ans = []
for i in range(H+2):
 ans.append([])
 for j in range(W+2):
   ans[i].append(0)

S = []
S.append([])
for j in range(W+2):
   S[0].append('.')
for i in range(H):
  s = input()
  s = list(s)
  s.insert(0,'.')
  s.append('.')
  S.append(s)
S.append([])
for j in range(W+2):
   S[-1].append('.')

for i in range(H+2):
  if((i != 0)and(i != H+1)):
   for j in range(W+2):
    if((j != 0)and(j != W+1)):
      if(S[i][j] == '#'):
        ans[i][j] = '#'
      else:
       if(S[i-1][j] == '#'):#上
        ans[i][j] += 1
       if(S[i+1][j] == '#'):#下
        ans[i][j] += 1
       if(S[i][j+1] == '#'):#右
        ans[i][j] += 1
       if(S[i][j-1] == '#'):#左
        ans[i][j] += 1 
       if(S[i-1][j+1] == '#'):#右上
        ans[i][j] += 1
       if(S[i-1][j-1] == '#'):#左上
        ans[i][j] += 1
       if(S[i+1][j+1] == '#'):#右下
        ans[i][j] += 1
       if(S[i+1][j-1] == '#'):#左下
        ans[i][j] += 1
        
for i in range(H+2):
  if((i != 0)and(i != H+1)):
   ans[i].pop(0)
   ans[i].pop(-1)
   for j in range(W):
    ans[i][j] = str(ans[i][j])
   print(''.join(ans[i]))