while n = gets.to_i
  break if n == 0
  date = 31.times.map{ [] }
  n.times do |i|
    gets.split.map(&:to_i)[1..-1].each{ |j| date[j] << i }
  end
  arr = []
  (1..30).each do |i|
    date[i].each{|p| arr << p}
    arr.uniq!
    if arr.size == n
      p i
      break
    end
  end
  p -1 if arr.size != n
end