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) then
p(l,m)=max(max(black(l-1,m),black(l+1,m)),max(black(l,m-1),black(l,m+1)))
if(p(l,m).eq.1)then
counts=counts+1
endif
endif
enddo
enddo
res=res+1
black(:,:)=p(:,:)
enddo

write(6,*)res

deallocate(s,black,p)

end