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.util.*;
class Main{
	static int H;
	static int W;
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		H = saori.saori_hayami();
		W = saori.saori_hayami();
		char[][] s = new char[H][W];
		int[][] moves = new int[H][W];
		int dx[] = { 0, 1, 0, -1 };
        int dy[] = { -1, 0, 1, 0 };

		Queue<Pair> que = new ArrayDeque<>();
		//int count = 0; 
		int ans =0;

		for(int i = 0;i < H;i++){
			String str = saori.nextHayami();
			for(int j = 0;j < W;j++){
				s[i][j] = str.charAt(j);
				moves[i][j] = -1;
				if(s[i][j] == '#'){
					Pair p = new Pair(i,j);
					que.add(p);
					moves[i][j] = 1;
					//count++;
				}
				
			}
		}

		while(que.size() > 0){
			int count = que.size();
			for(int j = 0;j < count;j++){
				Pair p = que.poll();
				for(int i=0;i<4;i++){
					int cx = p.x+dx[i];
					int cy = p.y+dy[i];
					if(cx >= 0 && cx <= H-1 && cy >= 0 && cy <= W-1 && s[cx][cy] == '.' && moves[cx][cy] == -1){
					  moves[cx][cy] = moves[p.x][p.y] + 1;
					  que.add(new Pair(cx,cy));
					}
				  }

			}
			ans++;
		}
		System.out.println(ans - 1);
		
    }
}

class Pair{
	int x;
	int y;
	public Pair(int x,int y){
		this.x = x;
		this.y = y;
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}