const
  inf = 1000000000;
var
  n, i, j, k, t, min, max, ans : integer;
begin
  reset(input, 'moose.in');
  rewrite(output, 'moose.out');
  read(n);
  assert((2 <= n) and (n <= 1000));
  ans := 0;
  for i := 1 to n - 1 do begin
    read(k);
    assert((2 <= k) and (k <= 1000));
    min := inf;
    for j := 1 to k - 1 do begin
      read(t);
      assert((1 <= t) and (t <= 10000));
      if (t < min) and (t >= ans) then begin
        min := t;
      end;
    end;
    if (min = inf) then begin
      writeln(-1);
      halt;
    end;
    ans := min;
  end;
  read(k);
  max := 0;
  for j := 1 to k - 1 do begin
    read(t);
    if (t > max) then begin
      max := t;
    end;
  end;
  if (max < ans) then begin
    writeln(-1);
  end else begin
    writeln(max);
  end;
end.