uses
  Math;
const
  maxn = 10000;
var
  n, m, i, j, ii, max, k : longint;
  b : array[1..maxn, 1..maxn] of longint;
  u : array[1..maxn] of boolean;
  a : array[1..maxn] of longint;
begin
  assign(input, 'theatre.in');
  assign(output, 'theatre.out');
  reset(input);
  rewrite(output);
  read(n, m);
  for i := 1 to n do begin
    for j := 1 to n do begin
      b[i][j] := m + 1;
    end;
  end;
  for i := 1 to m do begin
    read(k);
    for j := 1 to k do begin
      read(a[j]);
      u[a[j]] := true;
    end;
    for j := 1 to n do begin
      for ii := j + 1 to n do begin
        if (u[j] <> u[ii]) then begin
          b[j][ii] := min(b[j][ii], i);
        end;
      end;
    end;
    for j := 1 to k do begin
      u[a[j]] := false;
    end;
  end;
  for i := 1 to n do begin
    b[i][i] := 0;
    for j := 1 to i - 1 do begin
      b[i][j] := b[j][i];
    end;
    max := 0;
    for j := 1 to n do begin
      if (b[i][j] > max) then begin
        max := b[i][j];
      end;
    end;
    if (max = m + 1) then
      max := 0;
    write(max, ' ');  
  end;
end.
