program test
implicit none
character(len=100) :: s(100),ans(100)
character :: char
integer(8) :: i,j,h,w,is_bomb(0:100,0:100)=0

read(*,*) h,w
do i=1,h
	read(*,*) s(i)
	do j=1,w
		if(s(i)(j:j) == "#") then
			is_bomb(i,j) = 1
		endif
	enddo
enddo

do i=1,h
	do j=1,w
		if(is_bomb(i,j) == 1)then
			ans(i)(j:j) = "#"
		else
			write(char,'(I0)') sum(is_bomb(i-1:i+1,j-1:j+1))
			ans(i)(j:j) = char
		endif
	enddo
enddo

do i=1,h
	write(*,*) ans(i)(1:w)
enddo

end program