uses
  Math;
const
  maxn = 100000;
var
  iter, size, nc, n, m, i, j, ii, k : longint;
  color, csize, ans, a : array[1..maxn] of longint;
  
procedure qsort(l, r : longint);
var
  i, j, x, t : longint;
begin
  if (l >= r) then exit;
  i := l;
  j := r;
  x := color[a[random(r - l + 1) + l]];
  while (i <= j) do begin
    while (color[a[i]] < x) do i := i + 1;
    while (color[a[j]] > x) do j := j - 1;
    if (i <= j) then begin
      t := a[i]; a[i] := a[j]; a[j] := t;
      i := i + 1;
      j := j - 1;
    end;
  end;
  qsort(l, j);
  qsort(i, r);
end;  
  
begin
  assign(input, 'theatre.in');
  assign(output, 'theatre.out');
  reset(input);
  rewrite(output);
  read(n, m);
  for i := 1 to n do begin
    color[i] := 1;
  end;
  csize[1] := n;
  nc := 1;
  for iter := 1 to m do begin
    read(k);
    for j := 1 to k do begin
      read(a[j]);
    end;
    qsort(1, k);
    i := 1;
    while (i <= k) do begin
      j := i;
      while (j <= k) and (color[a[j]] = color[a[i]]) do begin
        j := j + 1;
      end;
      size := j - i;
      if (size <> csize[color[a[i]]]) then begin
        if (csize[color[a[i]]] - size = 1) then begin
          ans[color[a[i]]] := iter;
        end;  
        csize[color[a[i]]] := csize[color[a[i]]] - size;
        nc := nc + 1;
        csize[nc] := size;
        for ii := i to j - 1 do begin
          color[a[ii]] := nc;
        end;
        if (size = 1) then begin
          ans[nc] := iter;
        end;
      end;
      i := j;
    end;
  end;  
  for i := 1 to n do begin
    if (csize[color[i]] = 1) then begin
      write(ans[color[i]], ' ');
    end else begin
      write('0 ');
    end;
  end;
end.
