H, W = gets.split.map &:to_i
Board = $<.map{|s|
  s.chomp.chars.map{|c|c == ?# ? 1 : 0}
}

white = H * W
q = {}

H.times{|y|
  W.times{|x|
    if Board[y][x] == 1
      q[[y, x]] = 1
      Board[y][x] = 0
    end
  }
}

cnt = 0
while white > 0
  next_q = {}
  q.each{|(y, x), _|
    next if !y.between?(0, H-1)
    next if !x.between?(0, W-1)
    next if Board[y][x] == 1
    Board[y][x] = 1
    white -= 1
    [[0, 1], [0, -1], [1, 0], [-1, 0]].each{|dy, dx|
      yy = y + dy
      xx = x + dx
      next_q[[yy, xx]] = 1
    }
  }
  q = next_q
  cnt += 1
end
p cnt-1
