#include <bits/stdc++.h>
using namespace std;
int vis[500005];
vector<int> graph[500005];
void make_graph(int u, int v) {
  graph[u].push_back(v);
  graph[v].push_back(u);
}
void DFS(int start, int fg) {
  vis[start] = fg;
  for (int i = 0; i < graph[start].size(); i++) {
    int v = graph[start][i];
    if (!vis[v]) DFS(v, fg);
  }
}
map<int, int> m;
int main() {
  int i, j, k, n, e, u, v, cnt = 0;
  scanf("%d %d", &(n), &(e));
  for (i = 1; i <= e; i++) {
    scanf("%d", &(k));
    if (k > 0) {
      scanf("%d", &(u));
      for (j = 1; j < k; j++) {
        scanf("%d", &(v));
        make_graph(u, v);
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (!vis[i]) DFS(i, ++cnt);
  }
  for (i = 1; i <= n; i++) m[vis[i]]++;
  for (i = 1; i <= n; i++) {
    u = vis[i];
    cout << m[u] << " ";
  }
  cout << endl;
  return 0;
}
