[ height , width ] = list(map(int,input().split()))

input_map = []
output_map = [[0 for j in range(width)] for i in range(height)]

def is_sharp( input_map , x, y , width , height):
	if( x==-1 or y == -1 or x+1 >= width or y+1 >= height  ) :return 0
	
	if( input_map[y][x] == '#'):
		return 1
	else:
		 return 0

def count_sharp_num( input_map , x , y):
	count = 0
	count += is_sharp(input_map , x-1 , y-1 , width , height)
	count += is_sharp(input_map , x-1 , y , width , height)
	count += is_sharp(input_map , x-1 , y+1 , width , height)
	count += is_sharp(input_map , x , y-1 , width , height)
	count += is_sharp(input_map , x , y+1 , width , height)
	count += is_sharp(input_map , x+1 , y-1 , width , height)
	count += is_sharp(input_map , x+1 , y , width , height)
	count += is_sharp(input_map , x+1 , y+1 , width , height)
	return count

for i in range( height ):
	input_map.append( input() )


for x in range( width ):
	for y in range( height ):
		output_map[y][x] = count_sharp_num(input_map,x,y)
		if input_map[y][x] == '#':
			output_map[y][x] = '#'


for y in range(height):
	print( ''.join(map(str,output_map[y])))
