#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int dsu[5 * N];
int n, m, gg, kk;
int root(int u) {
  while (dsu[u] > 0) u = dsu[u];
  return u;
}
bool Union(int u, int v) {
  u = root(u);
  v = root(v);
  if (u == v) return false;
  if (dsu[u] > dsu[v]) swap(u, v);
  dsu[u] += dsu[v];
  dsu[v] = u;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) dsu[i] = -1;
  for (int i = 1; i <= m; ++i) {
    int u;
    cin >> u;
    if (u >= 1) cin >> gg;
    for (int i = 2; i <= u; ++i) {
      cin >> kk;
      Union(gg, kk);
    }
  }
  for (int i = 1; i <= n; ++i) {
    int u = root(i);
    cout << -dsu[u] << ' ';
  }
}
