#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 3;
bool vs[N] = {0}, vsg[N] = {0};
vector<int> list_friend[N];
vector<int> group[N];
int n, m, chl[N] = {0}, cnt = 0, stt[N];
int dfs(int u) {
  stt[u] = cnt;
  vs[u] = 1;
  int child = 1;
  for (int gr : group[u]) {
    if (!vsg[gr]) {
      vsg[gr] = 1;
      for (int v : list_friend[gr])
        if (!vs[v]) child += dfs(v);
    }
  }
  return chl[cnt] = child;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; ++j) {
      int u;
      scanf("%d", &u);
      list_friend[i].push_back(u);
      group[u].push_back(i);
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!vs[i]) {
      cnt++;
      dfs(i);
    }
  for (int i = 1; i <= n; ++i) printf("%d ", chl[stt[i]]);
  return 0;
}
