h=int(raw_input().split(' ')[0])
map=[]
for x in range(h):
 map.append(raw_input())
for row in range(h):
 for col in range(len(map[row])):
  count=0
  if map[row][col]=='.':
   for x in (-1,0,1):
    for y in (-1,0,1):
     if not (x==0 and y==0) and 0<=row+y<h and 0<=col+x<len(map[row]):
      if map[row+y][col+x]=='#':
       count+=1
   map[row]=map[row][:col]+str(count)+map[row][col+1:]
for row in map:
 print row