#include <bits/stdc++.h>
const int maxn = 5e5 + 5;
int fa[maxn], t[maxn], n, m, k, v, u, ev, eu;
int find(int n) { return n == fa[n] ? n : (fa[n] = find(fa[n])); }
void merge(int u, int v) {
  ev = find(v);
  eu = find(u);
  if (ev != eu) {
    fa[ev] = eu;
    t[eu] += t[ev];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) fa[i] = i, t[i] = 1;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &k);
    if (k) scanf("%d", &u);
    for (int j = 0; j < k - 1; ++j) {
      scanf("%d", &v);
      merge(u, v);
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d ", t[find(i)]);
  return 0;
}
