import Data.List

main = interact $ unlines . map (show' . save_your_privacy) . read' . lines
 where
  read' ("0":_) = []
  read' (n:xs) = (pss, ls) : read' xs'
   where
    (pss',(ls':xs')) = splitAt (read n) xs
    pss = map (\(m:ps)->(m,ps)) . zipWith (:) [1..] . map (tail . map read . words) $ pss'
    ls = tail . map read . words $ ls'
  show' rs = if length rs==1 then show (head rs) else "-1"

save_your_privacy (mpss,ls) = map fst (filter suspect mpss)
 where suspect (m,ps) = (intersect ps ls) == ls