import java.io.*;
import java.util.*;

public class moose_va_wa implements Runnable {
    public static void main(String[] args) {
        new Thread(new moose_va_wa()).run();
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }

        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public void solve() throws IOException {
        int n = nextInt();

        int[][] d = new int[n][];
        int min = 0;
        for (int i = 0; i < n; i++) {
            int k = nextInt();
            d[i] = new int[k - 1];
            for (int j = 0; j < k - 1; j++) {
                d[i][j] = nextInt();
            }

            Arrays.sort(d[i]);

            if (i == n - 1) {
                if (d[i][k - 2] < min) {
                    out.println("-1");
                    return;
                }
                out.println(d[i][k - 2]);
                return;
            }

            int z = Arrays.binarySearch(d[i], min);
            if (z >= 0) {
                continue;
            }

            min = d[i][-1 - z];
        }
    }

    public void run() {
        try {
            br = new BufferedReader(new FileReader("moose.in"));
            out = new PrintWriter("moose.out");

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}
