unittest
{
	assert( [ "3 5",
	          ".....",
	          ".#.#.",
	          "....." ].parse.expand.solve == "11211\n1#2#1\n11211" );
	assert( [ "3 5",
	          "#####",
	          "#####",
	          "#####" ].parse.expand.solve == "#####\n#####\n#####" );
	assert( [ "6 6",
	          "#####.",
	          "#.#.##",
	          "####.#",
	          ".#..#.",
	          "#.##..",
	          "#.#..." ].parse.expand.solve == "#####3\n#8#7##\n####5#\n4#65#2\n#5##21\n#4#310" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	auto sss = new char[][]( hw[ 0 ], hw[ 1 ] );
	foreach( ref ss; sss )
	{
		input.popFront;
		ss = input.front.strip.to!( char[] );
	}
	return tuple( hw[ 0 ], hw[ 1 ], sss );
}

auto solve( long h, long w, char[][] sss )
{
	foreach( y, ref ss; sss )
	{
		foreach( x, ref s; ss )
		{
			if( s == '#' ) continue;
			
			char mc = '0';
			
			if( 0 < y )
			{
				if( 0 < x     && sss[ y - 1 ][ x - 1 ] == '#' ) mc++;
				if( x < w - 1 && sss[ y - 1 ][ x + 1 ] == '#' ) mc++;
				if(              sss[ y - 1 ][ x     ] == '#' ) mc++;
			}
			
			if( y < h - 1 )
			{
				if( 0 < x     && sss[ y + 1 ][ x - 1 ] == '#' ) mc++;
				if( x < w - 1 && sss[ y + 1 ][ x + 1 ] == '#' ) mc++;
				if(              sss[ y + 1 ][ x     ] == '#' ) mc++;
			}
			
			if( 0 < x     && sss[ y     ][ x - 1 ] == '#' ) mc++;
			if( x < w - 1 && sss[ y     ][ x + 1 ] == '#' ) mc++;
			if(              sss[ y     ][ x     ] == '#' ) mc++;
			
			s = mc;
		}
	}
	
	return sss.join( "\n" );
}
