import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Yuki402 { static int H, W; static String[] S; static int[][] mp; public static void main(String[] args) { Scanner sc = new Scanner(System.in); H = sc.nextInt(); W = sc.nextInt(); S = new String[H + 2]; mp = new int[H + 2][W + 2]; sc.nextLine(); for (int i = 0; i < H + 2; i++) { if (i == 0 || i == H + 1) { S[i] = str(W + 2, '.'); } else { S[i] = sc.nextLine(); S[i] = '.' + S[i] + '.'; } } System.out.println(Search()); sc.close(); } static int Search() { int res = 0; int[] dh = new int[] { 0, 0, -1, -1, -1, 1, 1, 1 }; int[] dw = new int[] { 1, -1, 1, -1, 0, 1, -1, 0 }; Queue q = new LinkedList(); for (int i = 0; i < H + 2; i++) { for (int j = 0; j < W + 2; j++) { mp[i][j] = 0; if (S[i].charAt(j) == '.') { mp[i][j] = -1; q.add(new pair(i, j)); } } } while (!q.isEmpty()) { pair buf = q.poll(); int h = buf.getFirst(); int w = buf.getSecond(); for (int i = 0; i < 8; i++) { int nh = h + dh[i]; int nw = w + dw[i]; if (nh < 0 || nh >= H + 2) continue; if (nw < 0 || nw >= W + 2) continue; if (mp[nh][nw] == -1) continue; if (mp[h][w] == -1) { mp[nh][nw] = 1; q.add(new pair(nh, nw)); } else if (mp[nh][nw] > mp[h][w] + 1 || mp[nh][nw] == 0) { mp[nh][nw] = mp[h][w] + 1; q.add(new pair(nh, nw)); } res = Math.max(res, mp[nh][nw]); } } return res; } static String str(int n, char c) { String res = ""; for (int i = 0; i < n; i++) { res += c; } return res; } static class pair { private int first; private int second; pair(int f, int s) { this.first = f; this.second = s; } int getFirst() { return this.first; } int getSecond() { return this.second; } }; }