#include <bits/stdc++.h>
using namespace std;
int f[600005], b[600005];
int find(int n) {
  if (n == f[n]) {
    return n;
  }
  return f[n] = find(f[n]);
}
int main() {
  int i, j, m, n, s, w, k, w1;
  while (~scanf("%d %d", &n, &m)) {
    for (i = 0; i <= n; i++) f[i] = i;
    while (m--) {
      scanf("%d", &s);
      if (s--) {
        scanf("%d", &w);
        int y = find(w);
        while (s--) {
          scanf("%d", &k);
          int x = find(k);
          if (x != y) {
            f[x] = y;
          }
        }
      }
    }
    memset(b, 0, sizeof(b));
    for (i = 1; i <= n; i++) {
      b[find(i)]++;
    }
    for (i = 1; i < n; i++) {
      printf("%d ", b[find(i)]);
    }
    printf("%d\n", b[find(n)]);
  }
  return 0;
}
