#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int N = 5 * 1e5 + 10;
long long int parent[N];
long long int sizes[N];
long long int find_parent(long long int n) {
  while (parent[n] != n) n = parent[n];
  return n;
}
void unions(long long int a, long long int b) {
  long long int par_a = find_parent(a), par_b = find_parent(b);
  if (par_b == par_a) return;
  if (sizes[par_a] > sizes[par_b]) {
    sizes[par_a] += sizes[par_b];
    sizes[par_b] = 0;
    parent[par_b] = parent[par_a];
  } else {
    sizes[par_b] += sizes[par_a];
    sizes[par_a] = 0;
    parent[par_a] = parent[par_b];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
    sizes[i] = 1;
  }
  long long int a, b;
  for (long long int i = 0; i < m; i++) {
    cin >> a;
    long long int par;
    for (long long int j = 0; j < a; j++) {
      cin >> b;
      if (!j)
        par = b;
      else
        unions(b, par);
    }
  }
  for (long long int i = 0; i < n; i++)
    cout << sizes[find_parent(i + 1)] << " ";
  cout << endl;
  return 0;
}
