#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, A = 5e5 + 5;
vector<vector<long long>> v;
long long n, m, val;
long long ans[A];
bool vis[A], vis2[A];
void DFS(long long node) {
  if (vis[node]) return;
  vis[node] = 1;
  for (auto child : v[node]) {
    if (vis[child]) continue;
    val++;
    DFS(child);
  }
}
void DFSmemo(long long node) {
  if (vis2[node]) return;
  vis2[node] = 1;
  for (auto child : v[node]) {
    if (vis2[child]) continue;
    ans[child] = val;
    DFSmemo(child);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  v.resize(n + 2);
  for (int i = 0; i < m; i++) {
    long long g, x, y;
    cin >> g;
    if (g != 0) cin >> x;
    for (int j = 1; j < g; j++) {
      cin >> y;
      v[x].push_back(y), v[y].push_back(x);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 0) {
      val = 1;
      DFS(i);
      DFSmemo(i);
    } else
      val = ans[i];
    cout << val << " ";
  }
  return 0;
}
