#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 1;
const long long INF = 1e9 + 7;
const long long inf = 1e18;
vector<long long> adj[N];
long long vis[N];
long long ans[N];
long long ct;
void dfs(long long node) {
  vis[node] = ct;
  ans[ct]++;
  for (auto it : adj[node]) {
    if (!vis[it]) {
      dfs(it);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long x;
    cin >> x;
    long long count = 0, temp;
    while (x--) {
      long long a;
      cin >> a;
      if (count == 0) {
        temp = a;
      }
      if (count > 0) {
        adj[temp].push_back(a);
        adj[a].push_back(temp);
        temp = a;
      }
      count++;
    }
    count = 0;
  }
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      ct++;
      dfs(i);
    }
    cout << ans[vis[i]] << " ";
  }
}
