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.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int[][] queue = new int[m * n][2];
        int p, q;
        p = q = 0;
        char[][] grid = new char[m][n];
        int[][] d = new int[m][n];
        for (int i = 0; i < m; ++i) {
            grid[i] = scanner.next().toCharArray();
            for (int j = 0; j < n; ++j) {
                d[i][j] = -1;
                if (grid[i][j] == '#') {
                    d[i][j] = 0;
                    queue[q][0] = i;
                    queue[q++][1] = j;
                }
            }
        }
        final int[] rMove = new int[]{1, -1, 0, 0};
        final int[] cMove = new int[]{0, 0, 1, -1};
        while (p < q) {
            int r = queue[p][0];
            int c = queue[p][1];
            for (int i = 0; i < 4; ++i) {
                int newR = r + rMove[i];
                int newC = c + cMove[i];
                if (newR >= 0 && newR < m && newC >= 0 && newC < n && d[newR][newC] < 0) {
                    d[newR][newC] = d[r][c] + 1;
                    queue[q][0] = newR;
                    queue[q++][1] = newC;
                }
            }
            ++p;
        }
        writer.println(d[queue[q - 1][0]][queue[q - 1][1]]);
        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}