import java.util.Scanner; import java.util.Queue; import java.util.ArrayDeque; class Yuki2_4{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); int map[][] = new int[H + 4][W + 4]; Queue que = new ArrayDeque(); for(int i = 2; i <= H + 1; i++){ String input = sc.next(); for(int j = 2; j <= W + 1; j++){ if(input.charAt(j - 2) == '#'){ map[i][j] = 1510; }else{ que.add(0); que.add(j); que.add(i); } } } for(int i = 2; i <= H + 1; i++){ que.add(0); que.add(1); que.add(i); que.add(0); que.add(W + 2); que.add(i); } for(int i = 2; i <= W + 1; i++){ que.add(0); que.add(i); que.add(1); que.add(0); que.add(i); que.add(H + 2); } int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; int max = 0; while(!que.isEmpty()){ int distance = que.poll(); int x = que.poll(); int y = que.poll(); for(int i = 0; i < 8; i++){ int nx = x + dx[i]; int ny = y + dy[i]; if(map[ny][nx] > distance + 1){ max = Math.max(max, map[ny][nx] = distance + 1); que.add(distance + 1); que.add(nx); que.add(ny); } } } System.out.println(max); } }