#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 5e18;
const long double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long double rad(long double x) { return x * pi / 180.0; }
bool isleft(pair<long long, long long> a, pair<long long, long long> b,
            pair<long long, long long> c) {
  long long det = (b.first - a.first) * (c.second - a.second) -
                  (c.first - a.first) * (b.second - a.second);
  if (det >= 0) return true;
  if (det < 0) return false;
  return false;
}
long long exp(long long a, long long b) {
  long long result = 1;
  while (b > 0) {
    if (b & 1) result = mod(result * a, MOD);
    b >>= 1;
    a = mod(a * a, MOD);
  }
  return result;
}
long long grp[567891];
bool flag[567891];
vector<long long> adj[567891];
vector<long long> ps[567891];
long long ans[567891];
long long cnt;
void bfs(long long n, long long val) {
  queue<long long> fila;
  grp[n] = val;
  cnt++;
  for (long long &i : ps[n]) {
    fila.push(i);
    flag[i] = true;
  }
  while (!fila.empty()) {
    long long g = fila.front();
    fila.pop();
    for (long long &i : adj[g]) {
      if (grp[i] != -1) continue;
      grp[i] = val;
      cnt++;
      for (long long &j : ps[i]) {
        if (!flag[j]) {
          fila.push(j);
          flag[j] = true;
        }
      }
    }
  }
}
void solve() {
  for (long long i = 0; i < 567891; i++) {
    flag[i] = false;
    grp[i] = -1;
  }
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long q;
    cin >> q;
    while (q--) {
      long long x;
      cin >> x;
      adj[i].push_back(x);
      ps[x].push_back(i);
    }
  }
  long long aux = 1;
  for (long long i = 1; i <= n; i++) {
    if (grp[i] == -1) {
      cnt = 0;
      bfs(i, aux);
      ans[grp[i]] = cnt;
      aux++;
    }
  }
  for (long long i = 1; i <= n; i++) {
    cout << ans[grp[i]] << ' ';
  }
  cout << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) solve();
}
