program agc033a
  implicit none
  character(1000) s
  integer h,w,x,y
  integer,allocatable :: grid(:,:)

  read *,h,w
  allocate(grid(w,h))

  do y = 1,h
     read *,s
     do x = 1,w
        grid(x,y) = merge(0,1000000,s(x:x)=='#')
     end do
  end do

  do x = 2,w
     grid(x,:) = merge(grid(x-1,:)+1,grid(x,:),grid(x,:)-grid(x-1,:)>1)
     grid(w-x+1,:) = merge(grid(w-x+2,:)+1,grid(w-x+1,:),grid(w-x+1,:)-grid(w-x+2,:)>1)
  end do

  do y = 2,h
     grid(:,y) = merge(grid(:,y-1)+1,grid(:,y),grid(:,y)-grid(:,y-1)>1)
     grid(:,h-y+1) = merge(grid(:,h-y+2)+1,grid(:,h-y+1),grid(:,h-y+1)-grid(:,h-y+2)>1)
  end do

  print *,maxval(grid)
end program agc033a
