#include <bits/stdc++.h>
using namespace std;
int parent[500001], size[500001];
int find_set(int a) {
  if (a == parent[a]) return a;
  return parent[a] = find_set(parent[a]);
}
void union_set(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (size[a] > size[b]) {
    parent[b] = a;
    size[a] += size[b];
  } else {
    parent[a] = b;
    size[b] += size[a];
  }
}
int main() {
  int n, m, i;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    parent[i] = i;
    size[i] = 1;
  }
  while (m--) {
    int k, f;
    cin >> k;
    if (k == 0) continue;
    cin >> f;
    for (i = 2; i <= k; i++) {
      int a;
      cin >> a;
      if (find_set(f) != find_set(a)) union_set(f, a);
    }
  }
  for (i = 1; i <= n; i++) {
    cout << size[find_set(i)] << " ";
  }
  return 0;
}
