while n = gets.to_i
  break if n == 0
  date = [0]*31
  res = -1
  n.times do |i|
    gets.split.map(&:to_i)[1..-1].each{ |j| date[j] += 1<<i }
  end
  piece = n.times.map{ |i| 1<<i }
  date.each_with_index do |d, i|
    tmp = 0
    piece.each{ |p| tmp |= p if d & p != 0 }
    if tmp >= (1<<n) - 1
      res = i
      break
    end
    piece.map.with_index{ |p, i| piece[i] = tmp if d & p != 0}
  end
  p res
end