Problem: 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.

Examples

Input

3 3
...
.#.
...


Output

2


Input

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


Output

3

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int H;
    static int W;

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        int[] hw = in.readLineAsIntArray();
        H = hw[0];
        W = hw[1];
        char[][] A = new char[H][W];
        for (int i = 0; i < H; i++) {
            String l = in.readLine();
            A[i] = l.toCharArray();
        }

        int[] turns = new int[H * W];
        Arrays.fill(turns, -1);
        Queue<Integer> queue = new ArrayDeque<>();

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (A[i][j] == '#') {
                    int addr = addr(i, j);
                    turns[addr] = 0;
                    queue.add(addr);
                }
            }
        }
        int turn = 0;
        while (!queue.isEmpty()) {
            int addr = queue.poll();
            turn = Math.max(turn, turns[addr]);
            int row = addr / W;
            int col = addr % W;
            if (row > 0 && turns[addr(row - 1, col)] == -1) {
                turns[addr(row - 1, col)] = turns[addr] + 1;
                queue.add(addr(row - 1, col));
            }
            if (row < H - 1 && turns[addr(row + 1, col)] == -1) {
                turns[addr(row + 1, col)] = turns[addr] + 1;
                queue.add(addr(row + 1, col));
            }
            if (col > 0 && turns[addr(row, col - 1)] == -1) {
                turns[addr(row, col - 1)] = turns[addr] + 1;
                queue.add(addr(row, col - 1));
            }
            if (col < W - 1 && turns[addr(row, col + 1)] == -1) {
                turns[addr(row, col + 1)] = turns[addr] + 1;
                queue.add(addr(row, col + 1));
            }
        }
        System.out.println(turn);
    }

    int addr(int row, int col) {
        return row * W + col;
    }

    int row(int addr) {
        return addr / W;
    }

    int col(int addr) {
        return addr % W;
    }

    static class CustomReader extends BufferedReader {

        private static final int DEFAULT_BUF_SIZE = 2048;
        // private static final int DEFAULT_BUF_SIZE = 4096;
        // private static final int DEFAULT_BUF_SIZE = 8192;
        //private static final int DEFAULT_BUF_SIZE = 16384;
        // private static final int DEFAULT_BUF_SIZE = 1048576;

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in), DEFAULT_BUF_SIZE);
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public long[] readLineAsLongArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            long[] longArray = new long[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                longArray[i] = Long.parseLong(strArray[i]);
            }
            return longArray;
        }


        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }
    }
}