read h w;
s=(`dd`);
dx=(0 1 0 -1 1 1 -1 -1);
dy=(1 0 -1 0 1 -1 1 -1);
for((i=0;i<h;i++))do
	for((j=0;j<w;j++))do
		if [ ${s[$i]:$j:1} = "." ];then
			c=0;
			for((r=0;r<8;r++))do
				tx=$[i+${dx[r]}];
				ty=$[j+${dy[r]}];
				if [ $tx -ge 0 -a $ty -ge 0 -a $tx -lt $h -a $ty -lt $w ];then
					if [ ${s[$tx]:$ty:1} = "#" ];then
						c=$[c+1];
					fi
				fi
			done
			echo -n $c;
		else
			echo -n ${s[$i]:$j:1};
		fi
	done
	echo '';
done