#include <bits/stdc++.h>
using namespace std;
int pm[50000010];
int ff(int v) {
  while (v != pm[v]) {
    int t = pm[v];
    pm[v] = pm[pm[v]];
    v = t;
  }
  return v;
}
void uf(int a, int b) {
  int pa = ff(a);
  int pb = ff(b);
  if (pa == pb) return;
  pm[pb] = pa;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i <= n; i++) pm[i] = i;
  for (int i = 1; i <= m; i++) {
    int a;
    cin >> a;
    int y;
    for (int j = 0; j < a; j++) {
      int x;
      cin >> x;
      if (j == 0)
        y = x;
      else
        uf(y, x);
    }
  }
  for (int i = 1; i <= n; i++) {
    mp[ff(i)]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << mp[ff(i)] << " ";
  }
  return 0;
}
