H,W = gets.split.map(&:to_i)

dp =  Array.new(H){Array.new(W, -1)}
visited = Array.new(H){Array.new(W, false)}

search_range =[]

H.times do |i|
  grid = gets.chomp
  for j in 0..W-1 do
    if grid[j] == "#"
      dp[i][j] = 0
      visited[i][j] = true
      search_range << [i,j]
    end
  end
end

dxy = [
  [0,1],
  [0,-1],
  [1,0],
  [-1,0]
]
max = 0

while !search_range.empty? do
  x, y = search_range.shift
  dxy.each do |dx, dy|
    next if x+dx <0 || x+dx >H-1 || y+dy < 0 || y+dy >W-1
    if visited[x+dx][y+dy] == false
      dp[x+dx][y+dy] = dp[x][y] + 1
      max = dp[x+dx][y+dy] if max < dp[x+dx][y+dy]
      search_range.push([x+dx, y+dy])
      visited[x+dx][y+dy] = true
    end
  end
end

puts max
