#include <bits/stdc++.h>
const int N = 5e5 + 5;
int s[N], num[N];
int find(int x) {
  if (x != s[x]) s[x] = find(s[x]);
  return s[x];
}
void built(int x, int y) {
  x = find(s[x]), y = find(s[y]);
  if (x != y) {
    if (num[x] >= num[y]) {
      s[y] = x;
      num[x] += num[y];
    } else {
      s[x] = y;
      num[y] += num[x];
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    s[i] = i;
    num[i] = 1;
  }
  while (m--) {
    int t, x, y;
    scanf("%d", &t);
    if (t > 0) scanf("%d", &x);
    --t;
    for (int i = 0; i < t; ++i) {
      scanf("%d", &y);
      built(x, y);
    }
  }
  for (int i = 1; i <= n; ++i) {
    int x = find(i);
    printf("%d ", num[x]);
  }
  return 0;
}
