#include <bits/stdc++.h>
using namespace std;
int num[600000], ans[600000];
int find(int x) { return x == num[x] ? x : num[x] = find(num[x]); }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) num[i] = i;
  int k, x, q, p;
  while (m--) {
    scanf("%d", &k);
    if (!k) continue;
    scanf("%d", &p);
    for (int i = 1; i < k; i++) {
      scanf("%d", &q);
      int dx = find(p), dy = find(q);
      if (dx != dy) {
        num[dx] = dy;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    ans[num[i] = find(i)]++;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[num[i]]);
  }
}
