Problem:
Score : 300 points

Problem Statement

You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black.
HW characters from A_{11} to A_{HW} represent the colors of the squares.
A_{ij} is # if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is . if that square is white.

We will repeatedly perform the following operation until all the squares are black:

Every white square that shares a side with a black square, becomes black.

Find the number of operations that will be performed.
The initial grid has at least one black square.

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

After one operation, all but the corners of the grid will be black. After one more operation, all the squares will be black.

Sample Input 2

6 6
..#..#
......
#..#..
......
.#....
....#.

Sample Output 2

3

Solution in Common Lisp (SBCL 1.1.14) (judge verdict: Runtime Error)

(declaim (optimize (debug 0) (safety 0) (speed 3)))
(defun blacken (grid queue1 queue2 cnt)
  (loop while (< 0 (length queue1)) do
        (loop
          with i = (vector-pop queue1)
          with j = (vector-pop queue1)
          for (a b) in '((0 1) (0 -1) (1 0) (-1 0)) do
            (if (< (1+ cnt) (aref grid (+ i a) (+ j b)))
              (progn
                (setf (aref grid (+ i a) (+ j b)) (1+ cnt))
                (vector-push-extend (+ i a) queue2)
                (vector-push-extend (+ j b) queue2)))))
  (if (= 0 (length queue2))
    cnt
    (blacken grid queue2 queue1 (1+ cnt))))

(defun main ()
  (let* ((h (read))
         (w (read))
         (grid (make-array (list (+ h 2) (+ w 2))
                           :initial-element 0))
         (queue (make-array 0 :fill-pointer 0 :adjustable t)))
    (loop for i from 1 to h do
          (loop for j from 1 to w
                for c in (concatenate 'list (read-line)) do
                (if (equal c #\.)
                  (setf (aref grid i j) 9999999)
                  (progn
                    (setf (aref grid i j) 0)
                    (vector-push-extend i queue)
                    (vector-push-extend j queue)))))
    (format t "~a~%" 
      (blacken grid
               queue
               (make-array 0 :fill-pointer 0 :adjustable t)
               0))))
(main)