#include <bits/stdc++.h>
using namespace std;
map<long long, set<long long> > g;
vector<long long> b(500001, 0);
int32_t main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long k;
    cin >> k;
    vector<long long> p(k, 0);
    for (long long i = 0; i < k; i++) {
      cin >> p[i];
    }
    sort(p.begin(), p.end());
    for (long long i = 1; i < k; i++) {
      g[p[0]].insert(p[i]);
      g[p[i]].insert(p[0]);
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (b[i] == 0) {
      long long c = 0;
      queue<long long> q;
      q.push(i);
      set<long long> s;
      b[i] = -1;
      c++;
      s.insert(i);
      while (!q.empty()) {
        long long p = q.front();
        q.pop();
        for (auto s1 : g[p]) {
          if (b[s1] == 0) {
            b[s1] = -1;
            c++;
            s.insert(s1);
            q.push(s1);
          }
        }
      }
      for (auto s1 : s) {
        b[s1] = c;
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}
