{$apptype console}

const
    inf = 1000000000;

var
    n, k, i, j, d : longint;
    minVal, cur : longint;    

begin
    reset(input, 'moose.in');
    rewrite(output, 'moose.out');
    read(n);
    assert ((2 <= n) and (n <= 1000));

    cur := 0;
    for i := 1 to n - 1 do begin
        read(k);
        assert ((2 <= k) and (k <= 1000));

        minVal := inf;
        for j := 1 to k - 1 do begin
            read(d);
            assert ((1 <= d) and (d <= 10000));

            if (d >= cur) and (d < minVal) then
                minVal := d;
        end;
        if (minVal = inf) then begin
            writeln(-1);
            exit;
        end;
        cur := minVal;    
    end;

    read(k);
    assert ((2 <= k) and (k <= 1000));

    minVal := -1;
    for j := 1 to k - 1 do begin
        read(d);
        assert ((1 <= d) and (d <= 10000));

        if (d >= cur) and (d > minVal) then
            minVal := d;
    end;
    if (minVal = -1) then begin
        writeln(-1);
        exit;
    end;
    cur := minVal;    
    

    writeln(cur);
    close(input);
    close(output);
end.