#include <bits/stdc++.h>
using namespace std;
int const Max = 5e5 + 10;
int par[Max], cnt[Max], rnk[Max], n;
int pos = 0;
map<string, int> mp;
void make_set() {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    cnt[i] = 1;
    rnk[i] = 0;
  }
}
int find_parent(int x) {
  if (x != par[x]) par[x] = find_parent(par[x]);
  return par[x];
}
int make_union(int u, int v) {
  if ((u = find_parent(u)) != (v = find_parent(v))) {
    if (rnk[u] < rnk[v]) {
      cnt[v] += cnt[u];
      par[u] = par[v];
    } else {
      rnk[u] = max(rnk[u], rnk[v] + 1);
      cnt[u] += cnt[v];
      par[v] = par[u];
    }
  }
}
int main() {
  int m, k;
  scanf("%d %d", &n, &m);
  make_set();
  while (m--) {
    scanf("%d", &k);
    int u = -1;
    int v;
    while (k--) {
      scanf("%d", &v);
      v--;
      if (u != -1) make_union(u, v);
      u = v;
    }
  }
  for (int i = 0; i < n; i++) printf("%d ", cnt[find_parent(i)]);
  puts("");
}
