#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500010;
int pa[MAXN], num[MAXN];
int n, m, k, a, b;
void init() {
  for (int i = 1; i <= n; i++) {
    pa[i] = i;
    num[i] = 1;
  }
}
int find(int x) {
  while (x != pa[x]) x = pa[x];
  return x;
}
void nuio(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) {
    if (fx < fy) {
      pa[fy] = fx;
      num[fx] += num[fy];
    } else {
      pa[fx] = fy;
      num[fy] += num[fx];
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  init();
  for (int i = 1; i <= m; i++) {
    cin >> k;
    if (0 != k) cin >> a;
    for (int j = 1; j < k; j++) {
      cin >> b;
      nuio(a, b);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i == n)
      cout << num[find(i)] << endl;
    else
      cout << num[find(i)] << " ";
  }
  return 0;
}
