H, W = map(int, raw_input().split()) board = ['.'*(W+2)] for i in xrange(H): board.append('.'+raw_input()+'.') board.append('.'*(W+2)) frontier = set() visited = set() for i in xrange(H+2): for j in xrange(W+2): if board[i][j] == '.': frontier.add((i, j)) dr = [-1, -1, -1, 0, 0, 1, 1, 1] dc = [-1, 0, 1, -1, 1, -1, 0, 1] ans = 0 while len(visited) < (H+2)*(W+2): ans += 1 new_frontier = set() for r, c in frontier: for i in xrange(8): nr, nc = r+dr[i], c+dc[i] if nr < 0 or nr >= H+2 or nc < 0 or nc >=W+2: continue if (nr, nc) in visited or (nr, nc) in frontier: continue new_frontier.add((nr, nc)) visited |= frontier frontier = set(new_frontier) print ans-1