while n = gets.to_i
  break if n == 0
  day = 31.times.map{ [] }
  res = -1
  n.times do |i|
    gets.split.map(&:to_i)[1..-1].each{ |d| day[d] <<i }
  end
  pce = n.times.map{ |i| 1<<i }
  day.each_with_index do |d, i|
    cur = 0
    pce.each_with_index{ |p, i| cur |= p if d.include?(i) }
    if cur == (1<<n) - 1
      res = i
      break
    end
    pce.each_with_index{ |p, i| pce[i] = cur if d.include?(i) }
  end
  p res
end