#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void print1(T... t) {
  ((cout << t << " "), ...);
}
template <typename... T>
void print2(T... t) {
  vector<vector<long long>> ans = {t...};
  for (long long i = 0; i < (long long)ans.size(); i++) {
    if (i != 0)
      cout << "\t\t";
    else
      cout << "\t";
    for (long long j = 0; j < (long long)ans[i].size(); j++) {
      cout << ans[i][j] << " ";
    }
    if (i != (long long)ans.size() - 1) cout << endl;
  }
}
template <typename T>
void printV(T vec) {
  for (int i = 0; i < (long long)vec.size(); i++)
    cout << vec[i] << " " << flush;
  cout << endl;
}
const int INF = 1e9 + 5;
template <typename T>
void itR(T map) {
  for (auto itr = map.begin(); itr != map.end(); itr++) {
    cout << " [ "
            "itr->first, itr->second"
         << " : ";
    print1(itr->first, itr->second);
    cout << "]" << endl;
    ;
  }
  cout << endl;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<long long> node(n + 1);
  vector<long long> size(n + 1, 1);
  for (int i = 0; i < (long long)n + 1; i++) node[i] = i;
  for (long long i = 0; i < m; i++) {
    long long k;
    cin >> k;
    vector<long long> veck(k);
    for (int q = 0; q < (long long)k; q++) cin >> veck[q];
    for (long long j = 1; j < k; j++) {
      long long temp = veck[j];
      while (temp != node[temp]) {
        temp = node[temp];
      }
      long long temp1 = veck[0];
      while (temp1 != node[temp1]) {
        temp1 = node[temp1];
      }
      if (size[temp1] > size[temp]) {
        node[temp] = node[temp1];
        size[temp1]++;
      } else {
        node[temp1] = node[temp];
        size[temp]++;
      }
    }
  }
  map<long long, long long> mp;
  for (long long i = 1; i <= n; i++) {
    long long temp = i;
    while (temp != node[temp]) {
      temp = node[temp];
    }
    mp[temp]++;
  }
  for (long long i = 1; i <= n; i++) {
    long long temp = i;
    while (temp != node[temp]) {
      temp = node[temp];
    }
    cout << mp[temp] << " ";
  }
  cout << endl;
}
int main() {
  cout << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
