#include <bits/stdc++.h>
using namespace std;
long long mM(long long a, long long b, long long mod) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}
long long fpow(long long first, long long second, long long p = 998244353) {
  first = first % p;
  long long res = 1;
  while (second) {
    if (second & 1) res = (res * first) % p;
    res %= p;
    if (res < 0) res = (res + p) % p;
    second = second >> 1;
    first = (first * first) % p;
    if (first < 0) first = (first + p) % p;
    first %= p;
  }
  return res;
}
long long inv(long long n, long long p) { return fpow(n, p - 2, p); }
long long modmul(long long first, long long second, long long p = 998244353) {
  return (first * second) % p;
}
long long modadd(long long first, long long second, long long p = 998244353) {
  if (first >= p) first -= p;
  if (second >= p) second -= p;
  long long temp = first + second;
  if (temp >= p) temp -= p;
  if (temp < 0) temp = temp + p;
  return temp;
}
vector<long long> ro(500005, -1), sz(500005, 1);
void init() {
  for (int i = 1; i <= 500000; i++) ro[i] = i;
}
long long root(long long n) {
  if (ro[n] == n) return n;
  return ro[n] = root(ro[n]);
}
void join(long long a, long long b) {
  a = root(a);
  b = root(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    ro[b] = a;
    sz[a] += sz[b];
  }
}
int main() {
  long long t = 1, tc = 0;
  while (t--) {
    init();
    long long n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
      long long sz;
      cin >> sz;
      vector<long long> temp(sz);
      for (int j = 0; j < sz; j++) cin >> temp[j];
      for (int j = 1; j < sz; j++) join(temp[0], temp[j]);
    }
    for (int i = 1; i <= n; i++) cout << sz[root(i)] << " ";
    cout << "\n";
  }
}
