#include <bits/stdc++.h>
using namespace std;
bool vis[5 * 100005];
vector<int> adj[5 * 1000005];
int cnt = 0, num = 0;
void dfs(int u, map<int, int> &mp) {
  if (vis[u]) return;
  vis[u] = true;
  mp[u] = num;
  cnt++;
  for (auto v : adj[u])
    if (!vis[v]) dfs(v, mp);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    int u, v;
    if (k) cin >> u;
    k--;
    int temp = u;
    if (k > 0)
      while (k--) {
        cin >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        u = v;
      }
  }
  map<int, int> vv;
  map<int, int> comp;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i, vv);
      if (!cnt) cnt = 1;
      comp[num++] = cnt;
      cnt = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << comp[vv[i]] << ' ';
  }
}
