implicit none
integer h,w,counts
character(:),allocatable::s
integer i,j,k,l,m,area
integer,allocatable,dimension(:,:)::black,p
integer ::res=0

read(5,*)h,w
allocate(character(w)::s)
allocate(black(0:h+1,0:w+1),p(0:h+1,0:w+1))

black(:,:)=0
do i=1,h
read(5,*) s
do j=1,w
if(s(j:j).eq."#") then
black(i,j)=1
endif
enddo
enddo

counts=sum(black)
area=h*w
p(:,:)=black(:,:)

do while(counts .lt. area)
do l=1,h
do m=1,w
if(black(l,m).eq.0 .and.(black(l-1,m).eq.1 .or. black(l+1,m).eq.1 .or.black(l,m-1) .eq. 1 .or. black(l,m+1).eq.1)  ) then
p(l,m)=1
counts=counts+1
endif
enddo
enddo
res=res+1
black(:,:)=p(:,:)
enddo

write(6,*)res

deallocate(s,black,p)

end
