#include <bits/stdc++.h>
using namespace std;
map<int, int> root_sizes;
void init(int arr[], int size[], int N) {
  for (int i = 1; i <= N; i++) {
    arr[i] = i;
    size[i] = 1;
    root_sizes[i] = 1;
  }
}
int root(int arr[], int i) {
  while (arr[i] != i) {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}
bool find(int arr[], int A, int B) {
  if (root(arr, A) == root(arr, B))
    return true;
  else
    return false;
}
void weightedUnion(int arr[], int size[], int A, int B) {
  int root_A = root(arr, A);
  int root_B = root(arr, B);
  if (find(arr, A, B)) return;
  if (size[root_A] <= size[root_B]) {
    arr[root_A] = root_B;
    size[root_B] += size[root_A];
    root_sizes[root_B] = size[root_B];
    root_sizes.erase(root_A);
  } else {
    arr[root_B] = root_A;
    size[root_A] += size[root_B];
    root_sizes[root_A] = size[root_A];
    root_sizes.erase(root_B);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T-- > 0) {
    int N, M;
    cin >> N >> M;
    int arr[N + 1], size[N + 1];
    init(arr, size, N);
    unsigned long long ans = 1;
    while (M--) {
      int k;
      cin >> k;
      if (k > 0) {
        int rt;
        cin >> rt;
        for (int i = 2; i <= k; i++) {
          int y;
          cin >> y;
          weightedUnion(arr, size, rt, y);
        }
      }
    }
    for (int i = 1; i <= N; i++) cout << root_sizes[root(arr, i)] << " ";
  }
  return 0;
}
