#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int f[N], cnt[N];
int Find(int x) { return f[x] = (f[x] == x ? x : Find(f[x])); }
void join(int x, int y) {
  int fx = Find(x), fy = Find(y);
  if (fx != fy) {
    f[fx] = fy;
    cnt[fy] += cnt[fx];
  }
}
int main() {
  int n, m, t, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++) {
    f[i] = i;
    cnt[i] = 1;
  }
  while (m--) {
    scanf("%d", &t);
    if (t) {
      scanf("%d", &x);
      t--;
    }
    while (t--) {
      scanf("%d", &y);
      join(x, y);
    }
  }
  for (int i = 1; i <= n; i++) {
    int fi = Find(i);
    printf("%d", cnt[fi]);
    if (i == n) {
      printf("\n");
    } else {
      printf(" ");
    }
  }
  return 0;
}
