#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m, x, y, k;
int rk[N], p[N];
int getP(int a) { return (a == p[a] ? a : p[a] = getP(p[a])); }
void unite(int a, int b) {
  a = getP(a), b = getP(b);
  if (a == b) return;
  if (rk[a] < rk[b]) swap(a, b);
  p[b] = a;
  rk[a] += rk[b];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) rk[i] = 1, p[i] = i;
  while (m--) {
    cin >> k;
    int lst;
    for (int i = 0; i < k; i++) {
      cin >> x;
      x--;
      if (i != 0) unite(lst, x);
      lst = x;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << rk[getP(i)] << " ";
  }
}
