#include <bits/stdc++.h>
using namespace std;
int a[500000], b[500000];
int main() {
  int n, m, i, j, k, l, x, y, max;
  int f(int n);
  cin >> n >> m;
  for (i = 1; i <= n; i++) a[i] = i;
  for (int i = 0; i < m; i++) {
    cin >> x;
    if (x != 0) cin >> max;
    for (j = 1; j < x; j++) {
      cin >> y;
      k = f(max);
      l = f(y);
      if (max != y) a[k] = l;
      max = y;
    }
  }
  for (i = 1; i <= n; i++) b[f(i)]++;
  for (i = 1; i <= n; i++) {
    cout << b[f(i)];
    if (i != n) cout << " ";
  }
}
int f(int n) {
  if (n == a[n])
    return n;
  else
    return a[n] = f(a[n]);
}
