#include <bits/stdc++.h>
using namespace std;
int n, m;
int fa[500010];
int siz[500010];
int getfa(int p) { return p == fa[p] ? p : fa[p] = getfa(fa[p]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 0; i < m; i++) {
    int k;
    scanf("%d", &k);
    if (!k) continue;
    int root;
    scanf("%d", &root);
    if (k == 1) continue;
    int p = getfa(root);
    for (int j = 1; j < k; j++) {
      int a;
      scanf("%d", &a);
      int q = getfa(a);
      if (p != q) fa[q] = p;
    }
  }
  for (int i = 1; i <= n; i++) siz[getfa(i)]++;
  for (int i = 1; i <= n; i++)
    printf("%d%c", siz[getfa(i)], i == n ? '\n' : ' ');
  return 0;
}
