import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int h = Integer.parseInt(first[0]); int w = Integer.parseInt(first[1]); int w2 = w + 2; HashSet current = new HashSet<>(); for (int i = 0; i < w2; i++) { current.add(i); current.add((h + 1) * w2 + i); } char[][] field = new char[h][]; for (int i = 0; i < h; i++) { field[i] = br.readLine().toCharArray(); current.add((i + 1) * w2); current.add((i + 1) * w2 + w + 1); for (int j = 0; j < w; j++) { if (field[i][j] == '.') { current.add((i + 1) * w2 + j + 1); } } } HashSet used = new HashSet<>(); used.addAll(current); int idx = 0; while (used.size() < (h + 2) * (w + 2)) { HashSet next = new HashSet<>(); for (int x : current) { if (x % w2 > 0) { int tmp = x - 1; if (!used.contains(tmp)) { next.add(tmp); } if (x / w2 > 0) { int tmp2 = tmp - w2; if (!used.contains(tmp2)) { next.add(tmp2); } } if (x / w2 < h + 1) { int tmp2 = tmp + w2; if (!used.contains(tmp2)) { next.add(tmp2); } } } if (x % w2 < w + 1) { int tmp = x + 1; if (!used.contains(tmp)) { next.add(tmp); } if (x / w2 > 0) { int tmp2 = tmp - w2; if (!used.contains(tmp2)) { next.add(tmp2); } } if (x / w2 < h + 1) { int tmp2 = tmp + w2; if (!used.contains(tmp2)) { next.add(tmp2); } } } if (x / w2 > 0) { int tmp = x - w2; if (!used.contains(tmp)) { next.add(tmp); } } if (x / w2 < h + 1) { int tmp = x + w2; if (!used.contains(tmp)) { next.add(tmp); } } } idx++; used.addAll(next); current = next; } System.out.println(idx); } }