h,w=map(int,input().split())
s=[input() for i in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      continue
    count=0
    
    for dx in [-1,0,1]:
      for dy in [-1,0,1]:
        if 0<=i+dy<h and 0<=j+dx<w and s[i+dy][j+dx]=="#":
          count+=1
    s[i][j]=str(count)
    
for a in s:
  print(''.join(a))

