atcoder#AGC033A. [AGC033A] Darker and Darker

[AGC033A] Darker and Darker

Score : 300300 points

Problem Statement

You are given a grid of squares with HH horizontal rows and WW vertical columns, where each square is painted white or black. HWHW characters from A11A_{11} to AHWA_{HW} represent the colors of the squares. AijA_{ij} is # if the square at the ii-th row from the top and the jj-th column from the left is black, and AijA_{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

  • 1H,W10001 \leq H,W \leq 1000
  • AijA_{ij} is # or ..
  • The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

HH WW

A11A_{11}A12A_{12}......A1WA_{1W}

::

AH1A_{H1}AH2A_{H2}......AHWA_{HW}

Output

Print the number of operations that will be performed.

3 3
...
.#.
...
2

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

6 6
..#..#
......
#..#..
......
.#....
....#.
3