#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
  long long int i, j;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
long long int power(long long int x, long long int n, long long int mod) {
  if (x == 0) return 0;
  if (n == 0) return 1;
  if (n == 1) return x % mod;
  if (n % 2 == 0) {
    long long int temp = power(x, n / 2, mod);
    return (temp % mod * temp % mod) % mod;
  } else {
    long long int temp = power(x, n / 2, mod);
    return (x % mod * ((temp % mod * temp % mod) % mod) % mod) % mod;
  }
}
long long int findParent(long long int i, long long int parent[]) {
  if (parent[parent[i]] != parent[i]) parent[i] = findParent(parent[i], parent);
  return parent[i];
}
void unionNodes(long long int a, long long int b, long long int parent[],
                long long int size[]) {
  long long int parent_a = findParent(a, parent),
                parent_b = findParent(b, parent);
  if (parent_a == parent_b) return;
  if (size[parent_a] >= size[parent_b]) {
    size[parent_a] += size[parent_b];
    parent[parent_b] = parent_a;
  } else {
    size[parent_b] += size[parent_a];
    parent[parent_a] = parent_b;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m, i, j;
  cin >> n >> m;
  long long int arr[n + 1], size[n + 1];
  for (i = 1; i <= n; i++) {
    arr[i] = i;
    size[i] = 1;
  }
  for (i = 0; i < m; i++) {
    long long int k, temp;
    cin >> k;
    for (j = 0; j < k; j++) {
      long long int x;
      cin >> x;
      if (j == 0) {
        temp = x;
        continue;
      } else {
        unionNodes(x, temp, arr, size);
        temp = x;
      }
    }
  }
  map<long long int, long long int> mp;
  for (i = 1; i <= n; i++) mp[findParent(i, arr)]++;
  for (i = 1; i <= n; i++) cout << mp[findParent(i, arr)] << " ";
  cout << '\n';
  return 0;
}
