program ABC075B
    implicit none
    integer(8)::H,W,i,j,k
    integer(8),allocatable,dimension(:,:)::O
    integer(8),dimension(8)::dx=(/-1,0,1,-1,1,-1,0,1/)
    integer(8),dimension(8)::dy=(/-1,-1,-1,0,0,1,1,1/)
    character(50)::S
    read(5,*)H,W
    allocate(O(W,H))
    O=0

    do i=1,H
        read(5,*)S
        do j=1,W
            if(S(j:j)=='#')then
                O(j,i)=-1
                do k=1,8
                    if(j+dx(k)>=1 .and. j+dx(k)<=W .and. i+dy(k)>=1 .and. i+dy(k)<=H .and. O(j+dx(k),i+dy(k))/=-1)then
                        O(j+dx(k),i+dy(k))=O(j+dx(k),i+dy(k))+1
                    end if
                end do
            end if
        end do
    end do

    do i=1,H
        do j=1,W
            if(O(j,i)==-1)then
                write(*,fmt='(a)',advance='no') "#"
            else
                write(*,fmt='(i0)',advance='no') O(j,i)
            end if
        end do
        write(*,fmt='(a)') ""
    end do

end program ABC075B