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 {
    char[][] board = new char[1000][];
    int H,W;
    List<Integer> sharpx = new ArrayList<>();
    List<Integer> sharpy = new ArrayList<>();
    List<Integer> tmpSharpx = new ArrayList<>();
    List<Integer> tmpSharpy = new ArrayList<>();
    int countSharp;
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            H = sc.nextInt();
            W = sc.nextInt();
            countSharp = 0;

            for (int i = 0; i < H; i++) {
                board[i] = new char[1001];
                String input = sc.next();
                for (int j = 0; j < W; j++) {
                    board[i][j] = input.charAt(j);
                    if (board[i][j] == '#') {
                        sharpx.add(j);
                        sharpy.add(i);
                        countSharp++;
                    }
                }
            }

            int count = 0;

            while (countSharp < H * W) {
                tmpSharpx.clear();
                tmpSharpy.clear();
                for (int i = 0; i < sharpx.size(); i++) {
                    int sx = sharpx.get(i);
                    int sy = sharpy.get(i);
                    color(sx, sy);
                }
                sharpx.clear();
                sharpy.clear();
                sharpx.addAll(tmpSharpx);
                sharpy.addAll(tmpSharpy);
                count ++;
            }

            System.out.println(count);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void color (int x, int y) {
        if (x == 0) {
            if (board[y][x+1] == '.') {
                board[y][x + 1] = '#';
                tmpSharpx.add(x + 1);
                tmpSharpy.add(y);
                countSharp++;
            }
        } else if (x == W - 1) {
            if (board[y][x-1] == '.') {
                board[y][x - 1] = '#';
                tmpSharpx.add(x - 1);
                tmpSharpy.add(y);
                countSharp++;
            }
        } else {
            if (board[y][x+1] == '.') {
                board[y][x + 1] = '#';
                tmpSharpx.add(x + 1);
                tmpSharpy.add(y);
                countSharp++;
            }
            if (board[y][x-1] == '.') {
                board[y][x - 1] = '#';
                tmpSharpx.add(x - 1);
                tmpSharpy.add(y);
                countSharp++;
            }
        }

        if (y == 0) {
            if (board[y+1][x] == '.') {
                board[y + 1][x] = '#';
                tmpSharpx.add(x);
                tmpSharpy.add(y + 1);
                countSharp++;
            }
        } else if (y == H - 1) {
            if (board[y-1][x] == '.') {
                board[y-1][x] = '#';
                tmpSharpx.add(x);
                tmpSharpy.add(y-1);
                countSharp++;
            }
        } else {
            if (board[y+1][x] == '.') {
                board[y + 1][x] = '#';
                tmpSharpx.add(x);
                tmpSharpy.add(y + 1);
                countSharp++;
            }
            if (board[y-1][x] == '.') {
                board[y-1][x] = '#';
                tmpSharpx.add(x);
                tmpSharpy.add(y-1);
                countSharp++;
            }
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}