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

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

search_range =[]

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

max = 0

while !search_range.empty? do
  tmp = []
  search_range.each do |x,y|

    if x != 0 && dp[x-1][y] == -1
      dp[x-1][y] = dp[x][y] + 1
      max = dp[x-1][y] if max < dp[x-1][y]
      tmp << [x-1,y]
    end

    if x != H-1 && dp[x+1][y] == -1
      dp[x+1][y] = dp[x][y] + 1
      max = dp[x+1][y] if max < dp[x+1][y]
      tmp << [x+1,y]
    end

    if y != 0 && dp[x][y-1] == -1
      dp[x][y-1] = dp[x][y] + 1
      max = dp[x][y-1] if max < dp[x][y-1]
      tmp << [x,y-1]
    end

    if y != W-1 && dp[x][y+1] == -1
      dp[x][y+1] = dp[x][y] + 1
      max = dp[x][y+1] if max < dp[x][y+1]
      tmp << [x,y+1]
    end

  end
  search_range = tmp
end

puts max
