#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int f[maxn];
int k[maxn];
inline int Find(int x) {
  if (f[x] != x) {
    f[x] = Find(f[x]);
  }
  return f[x];
}
void init() {
  for (int i = 0; i < maxn; i++) {
    f[i] = i;
    k[i] = 1;
  }
}
int main() {
  int n, m;
  init();
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int t, tmp1, tmp;
    int r1, r2;
    scanf("%d", &t);
    if (t) {
      scanf("%d", &tmp1);
      r1 = Find(tmp1);
    }
    for (int j = 1; j < t; j++) {
      scanf("%d", &tmp);
      r2 = Find(tmp);
      if (r1 != r2) {
        k[r1] += k[r2];
        f[r2] = r1;
      }
    }
  }
  if (n) {
    printf("%d", k[Find(1)]);
  }
  for (int i = 2; i <= n; i++) {
    printf(" %d", k[Find(i)]);
  }
  printf("\n");
  return 0;
}
