#include <bits/stdc++.h>
using namespace std;
int Rank[500005], Parent[500005];
void MakeSet(int n) {
  for (int i = 1; i <= n; i++) {
    Parent[i] = i;
    Rank[i] = 1;
  }
}
int Find(int x) {
  if (Parent[x] != x) {
    Parent[x] = Find(Parent[x]);
  }
  return Parent[x];
}
void Union(int x, int y) {
  int xset = Find(x);
  int yset = Find(y);
  if (xset != yset) {
    Parent[yset] = xset;
    Rank[xset] = Rank[xset] + Rank[yset];
  }
}
int main() {
  int n, m, f;
  scanf("%d %d", &n, &m);
  MakeSet(n);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &f);
    int ar[f + 5];
    for (int j = 1; j <= f; j++) {
      scanf("%d", &ar[j]);
      if (j != 1) {
        Union(ar[j - 1], ar[j]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int ans = Rank[Find(i)];
    cout << ans << " ";
  }
}
