#include <bits/stdc++.h>
using namespace std;
long long arr[500001];
long long siz[500001];
void initialize(int n) {
  for (long long i = 1; i < n + 1; i++) {
    arr[i] = i;
    siz[i] = 1;
  }
}
int root(int a) {
  while (a != arr[a]) a = arr[a];
  return a;
}
void union1(int a, int b) {
  int r_a = root(a);
  int r_b = root(b);
  if (r_a == r_b) return;
  if (siz[r_a] > siz[r_b]) {
    arr[r_b] = arr[r_a];
    siz[r_a] += siz[r_b];
    siz[r_b] = 0;
  } else {
    arr[r_a] = arr[r_b];
    siz[r_b] += siz[r_a];
    siz[r_a] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  initialize(n);
  for (long long i = 0; i < m; i++) {
    int q;
    cin >> q;
    if (q == 0) {
      continue;
    }
    int a;
    cin >> a;
    q--;
    for (long long i = 0; i < q; i++) {
      int b;
      cin >> b;
      union1(a, b);
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    int r_i = root(i);
    cout << siz[r_i] << " ";
  }
  cout << endl;
}
