#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
struct DSU {
  vector<int> parent;
  vector<int> size;
  DSU(size_t sz) {
    parent.resize(sz + 1, -1);
    size.resize(sz + 1, -1);
  }
  void makeSet(int a) {
    parent[a] = a;
    size[a] = 1;
  }
  int getParent(int a) {
    return (parent[a] == a) ? a : (parent[a] = getParent(parent[a]));
  }
  void unite(int a, int b) {
    int pa = getParent(a);
    int pb = getParent(b);
    if (pa == pb) return;
    if (size[pb] > size[pa]) swap(pa, pb);
    parent[pb] = pa;
    size[pa] += size[pb];
  }
  int getSize(int a) { return size[getParent(a)]; }
};
void solve() {
  int n, m;
  cin >> n >> m;
  DSU dsu(n);
  for (int i = 1; i <= n; i++) dsu.makeSet(i);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    if (k == 0) continue;
    int prev;
    cin >> prev;
    for (int j = 1; j < k; j++) {
      int guy;
      cin >> guy;
      dsu.unite(prev, guy);
      prev = guy;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << dsu.getSize(i) << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
