#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 5e5 + 5;
inline int read() {
  int sum = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum * f;
}
int f[N], n, m, sz[N];
int find(int x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx ^ fy) {
    f[fx] = fy;
    sz[fy] += sz[fx];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    f[i] = i;
    sz[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int num;
    cin >> num;
    if (num == 0) continue;
    int x, y;
    cin >> x;
    for (int j = 1; j < num; j++) {
      cin >> y;
      merge(x, y);
    }
  }
  for (int i = 1; i <= n; i++) cout << sz[find(i)] << " ";
  return 0;
}
