#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 500005;
int parent[MAXN];
int size[MAXN];
void make_set(int v) {
  parent[v] = v;
  size[v] = 1;
}
int find_set(int v) {
  if (parent[v] == v)
    return v;
  else
    return parent[v] = find_set(parent[v]);
}
void union_set(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (size[a] < size[b]) swap(a, b);
    parent[b] = a;
    size[a] += size[b];
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) make_set(i);
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    if (k > 0) {
      vector<int> a;
      for (int j = 0; j < k; ++j) {
        int ki;
        cin >> ki;
        a.push_back(ki);
      }
      for (int j = 1; j < k; ++j) union_set(a[j], a[0]);
    }
  }
  for (int i = 1; i <= n; ++i) cout << size[find_set(i)] << " ";
  cout << endl;
  return 0;
}
