#include <bits/stdc++.h>
using namespace std;
long long parent[500005];
long long rank_[500005];
long long find_(long long x) {
  if (parent[x] == x) {
    return (x);
  } else
    return (parent[x] = find_(parent[x]));
}
void union_(long long x, long long y) {
  long long xroot = find_(x);
  long long yroot = find_(y);
  if (xroot != yroot) {
    parent[xroot] = yroot;
    rank_[yroot] += rank_[xroot];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(NULL));
  long long n, m;
  cin >> n >> m;
  vector<long long> vec[m];
  for (long long it = 0; it < m; it++) {
    long long k, val;
    cin >> k;
    for (long long i = 0; i < k; i++) {
      cin >> val;
      vec[it].push_back(val);
    }
  }
  for (long long i = 1; i <= n; i++) {
    parent[i] = i;
    rank_[i] = 1;
  }
  for (long long i = 0; i < m; i++) {
    long long par;
    if (vec[i].size() > 0) {
      par = vec[i][0];
    } else {
      continue;
    }
    for (long long j = 1; j < vec[i].size(); j++) {
      long long x = par;
      long long y = vec[i][j];
      union_(x, y);
    }
  }
  for (long long i = 1; i <= n; i++) {
    cout << rank_[find_(i)] << " ";
  }
  cout << endl;
  return 0;
}
