a,b=map(int,input().split())
c=[]
for i in range(a):
  c+=[list(input())]
for i in range(a):
  for j in range(b):
    if c[i][j]=='.':
      d=0
      for k in range(i-1,i+2):
        for l in range(j-1,j+2):
          if 0<=k and k<a and 0<=l and l<b:
            d+=c[k][l]=='#'
      c[i][j]=str(d)
for i in c:
  print(''.join(i))