program sample
    implicit none
    character(50)::s,t
    character::a
    integer(8) :: i,j,m,n,h,w
    integer(8),allocatable :: x(:,:),y(:)
    read(*,*)h,w
    allocate(x(0:h+1,0:w+1))
    x(:, :)=0
    do i=1,h
        read(*,*) s
        do j=1,w
            if (s(j:j) .eq. '#')then
                x(i,j)=-10
                x(i-1,j-1)=x(i-1,j-1)+1
                x(i,j-1)=x(i,j-1)+1
                x(i+1,j-1)=x(i+1,j-1)+1
                x(i-1,j)=x(i-1,j)+1
                x(i+1,j)=x(i+1,j)+1
                x(i-1,j+1)=x(i-1,j+1)+1
                x(i,j+1)=x(i,j+1)+1
                x(i+1,j+1)=x(i+1,j+1)+1
            end if
        end do
    end do
    do i=1,h
        t='0'
        do j=1,w
            if(x(i,j)<0)then
                t(j:j)='#'
            else
                write(a,'(i1)')x(i,j)
                t(j:j)=a
            end if

        end do
        write(*,'(a)') t

    end do

    
   
  
    stop
end program sample
  

