#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 10;
struct DSU {
  vector<int> p;
  DSU(int n) {
    p.resize(n);
    for (int i = 0; i < n; ++i) p[i] = i;
  }
  int find(int x) { return p[x] == x ? x : (p[x] = find(p[x])); }
  bool join(int u, int v) {
    int p1 = find(u), p2 = find(v);
    if (p1 != p2) {
      p[p1] = p2;
      return true;
    }
    return false;
  }
};
int n, m;
vector<int> vs[N + N];
void solve() {
  cin >> n >> m;
  DSU dsu(N + N);
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    int par = i + N;
    for (int j = 0; j < k; ++j) {
      int x;
      cin >> x, --x;
      dsu.join(par, x);
    }
  }
  vector<int> ids(N + N);
  for (int i = 0; i < n; ++i) {
    ids[dsu.find(i)]++;
  }
  for (int i = 0; i < n; ++i) {
    cout << ids[dsu.find(i)] << " ";
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  solve();
  return 0;
}
