h, w = gets.chomp.split(" ")
h = h.to_i
w = w.to_i
board = []
h.times do |i|
  board.push(gets.chomp.split(""))
end

def sprea(h, w, table, counter)
  flag = 0
  tmptable = []
  for i in table
    tmptable.push(i.dup)
  end

  h.times do |i|
    w.times do |j|
      if table[i][j] == "#"
        if i > 0
          if table[i-1][j] == "."
            tmptable[i-1][j] = "#"
	    flag = 1
	  end
	end
	if i < w
          if table[i+1][j] == "."
            tmptable[i+1][j] = "#"
	    flag = 1
	  end
	end
	if j > 0
          if table[i][j-1] == "."
            tmptable[i][j-1] = "#"
	    flag = 1
	  end
	end
	if j < h
	  if table[i][j+1] == "."
            tmptable[i][j+1] = "#"
	    flag = 1
	  end
	end
      end
    end
  end
  if flag == 1
    counter += 1
    sprea(h, w, tmptable, counter)
  else
    return counter
  end
end

num = 0
p sprea(h, w-1, board, num)