#include <bits/stdc++.h>
using namespace std;
int sz[500005], t[500005];
int root(int x) {
  if (t[x] == 0) return x;
  t[x] = root(t[x]);
  return t[x];
}
int main() {
  int n, m, i, k, x, rx, ry;
  cin >> n >> m;
  for (i = 1; i <= n; i++) sz[i] = 1;
  for (i = 1; i <= m; i++) {
    cin >> k;
    if (k == 0) continue;
    cin >> x;
    rx = root(x);
    k--;
    while (k--) {
      cin >> x;
      ry = root(x);
      if (ry == rx) continue;
      t[ry] = rx;
      sz[rx] += sz[ry];
      sz[ry] = 0;
    }
  }
  for (i = 1; i <= n; i++) {
    cout << sz[root(i)] << ' ';
  }
  return 0;
}
