#include <bits/stdc++.h>
using namespace std;
vector<int> parent, tamanho;
int root(int x) {
  while (x != parent[x]) x = parent[x];
  return x;
}
void join(int a, int b) {
  a = root(a);
  b = root(b);
  if (a == b) return;
  if (tamanho[a] < tamanho[b]) swap(a, b);
  parent[b] = a;
  tamanho[a] += tamanho[b];
}
int main() {
  int n, m;
  cin >> n >> m;
  parent = tamanho = vector<int>(n + 1);
  for (int i = 1; i <= n; i++) {
    tamanho[i] = 1;
    parent[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    int prev = -1;
    for (int j = 0; j < k; j++) {
      int foo;
      cin >> foo;
      if (j > 0) join(foo, prev);
      prev = foo;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << tamanho[root(i)] << ' ';
  }
  cout << '\n';
  return 0;
}
