require 'set'
loop do
    bl = false
    n = gets.to_i
    break if n == 0
    d = Array.new(n).map{Array.new(31,false)}
    n.times do |i|
        _, *dt = gets.split.map(&:to_i)
        dt.each do |dd|
            d[i][dd] = true
        end
    end
    m = Array.new(n).map{Array.new(31).map{Set.new}}
    m.each_with_index do |mm,i|
        mm[0].add(i)
    end
    1.upto(30) do |i|
        m.each do |mm|
            mm[i] = mm[i-1]
        end
        s = Set.new
        d.each_with_index do |dd,j|
            s.add(j) if dd[i]
        end
        s.each do |si|
            s.each do |sj|
                next if si == sj
                m[si][i] = m[si][i-1] + m[sj][i-1]
                m[sj][i] = m[si][i-1] + m[sj][i-1]
            end
        end
        n.times do |k|
            if Set.new((0...n).to_a).subset?(m[k][i])
                puts i
                bl = true
                break
            end
        end
        break if bl
    end
    puts "-1" if !bl
end