#include <bits/stdc++.h>
using namespace std;
const int __ = 5e5 + 5;
struct DisjointSetUnion {
  int pre[__];
  DisjointSetUnion() { clear(); }
  void un(int x, int y) {
    x = fd(x), y = fd(y);
    if (x == y) return;
    if (pre[x] > pre[y]) swap(x, y);
    pre[x] += pre[y], pre[y] = x;
  }
  int fd(int x) {
    if (pre[x] < 0) return x;
    return pre[x] = fd(pre[x]);
  }
  void clear() { memset(pre, -1, sizeof(pre)); }
} dsu;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); ++i) {
    int k, x;
    scanf("%d", &k);
    if (k) scanf("%d", &x);
    for (int i = (2); i <= (k); ++i) {
      int y;
      scanf("%d", &y);
      dsu.un(x, y);
    }
  }
  for (int i = (1); i <= (n); ++i) printf("%d ", -dsu.pre[dsu.fd(i)]);
  return 0;
}
