#include <bits/stdc++.h>
using namespace std;
long long parent[500005];
long long size[500005];
long long find_set(long long v) {
  if (parent[v] == v) {
    return v;
  } else {
    parent[v] = find_set(parent[v]);
    return parent[v];
  }
}
void merge_set(long long u, long long v) {
  u = find_set(u);
  v = find_set(v);
  if (u != v) {
    if (size[u] < size[v]) {
      parent[u] = v;
      size[v] += size[u];
    } else {
      parent[v] = u;
      size[u] += size[v];
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    parent[i] = i;
    size[i] = 1;
  }
  for (long long i = 0; i < m; i++) {
    long long k;
    cin >> k;
    if (k > 0) {
      long long first;
      cin >> first;
      for (long long i = 1; i < k; i++) {
        long long second;
        cin >> second;
        merge_set(first, second);
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    long long q = find_set(i);
    cout << size[q] << " ";
  }
  return 0;
}
