import java.util.Scanner; public class Yukicoder402 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt() + 2, w = sc.nextInt() + 2; String[] s = new String[h]; int[] map = new int[h * w]; int[] map_buf = new int[h * w]; int[] dx = {-1, 0, 1, -1, 1, -1, 0, 1}; int[] dy = {-1, -1, -1, 0, 0, 1, 1, 1}; for (int i = 0; i < h; i++) { if (i == 0 || i == h - 1) { for (int x = 0; x < w; x++) { map[i * w + x] = 0; map_buf[i * w + x] = 0; } } if (i == 0 || i == h - 1) continue; s[i] = sc.next(); for (int x = 0; x < w; x++) { if (x == 0 || x == w - 1) { map[i * w + x] = 0; map_buf[i * w + x] = 0; } else if (s[i].charAt(x - 1) == '.') { map[i * w + x] = 0; map_buf[i * w + x] = 0; } else { map[i * w + x] = 1; map_buf[i * w + x] = 1; } } } int cnt, k; for (k = 1; k < 1500; k++) { cnt = 0; for (int y = k; y < h - k; y++) { for (int x = k; x < w - k; x++) { if (map[y * w + x] == 1) { for (int p = 0; p < 8; p++) { if (map[(y + dy[p]) * w + (x + dx[p])] == 0) { map_buf[y * w + x] = 0; cnt++; break; } } } } } for (int y = k; y < h - k; y++) { for (int x = k; x < w - k; x++) { /* if (map[y * w + x] == 1) System.out.print("#"); else System.out.print("."); */ map[y * w + x] = map_buf[y * w + x]; } } if (cnt == 0) break; } System.out.println(k-1); } }