#include <bits/stdc++.h>
using namespace std;
long long root(long long Arr[], long long i) {
  while (Arr[i] != i) {
    Arr[i] = Arr[Arr[i]];
    i = Arr[i];
  }
  return i;
}
void wunion(long long arr[], unsigned long long size[], long long a,
            long long b) {
  long long roota = root(arr, a);
  long long rootb = root(arr, b);
  if (roota == rootb) return;
  if (size[roota] < size[rootb]) {
    arr[roota] = arr[rootb];
    size[rootb] += size[roota];
  } else {
    arr[rootb] = arr[roota];
    size[roota] += size[rootb];
  }
}
void findsize(long long arr[], unsigned long long size[], long long n) {
  for (long long i = 1; i <= n; i++) {
    size[i] = size[root(arr, i)];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, i;
  cin >> n >> m;
  long long arr[n + 1];
  unsigned long long size[n + 1];
  for (i = 0; i <= n; i++) {
    arr[i] = i;
    size[i] = 1;
  }
  while (m--) {
    long long a;
    cin >> a;
    long long k[a];
    for (i = 0; i < a; i++) {
      cin >> k[i];
    }
    for (i = 0; i < a - 1; i++) {
      wunion(arr, size, k[i], k[i + 1]);
    }
  }
  findsize(arr, size, n);
  for (i = 1; i <= n; i++) {
    cout << size[i] << " ";
  }
}
