#include <bits/stdc++.h>
using namespace std;
const int mx = 2e6;
vector<int> adj[mx];
int news[mx], visited[mx], now, ans, cnt = 0, n, m;
int dfs(int x) {
  if (visited[x]) return 0;
  visited[x] = cnt;
  int ans;
  if (x < n)
    ans = 1;
  else
    ans = 0;
  for (auto it : adj[x]) ans += dfs(it);
  return ans;
}
int main() {
  int m, idx;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &now);
    for (int j = 0; j < now; j++) {
      scanf("%d", &idx);
      idx--;
      adj[idx].push_back(i + n);
      adj[i + n].push_back(idx);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      cnt++;
      news[cnt] = dfs(i);
    }
    printf("%d ", news[visited[i]]);
  }
}
