#include <bits/stdc++.h>
using namespace std;
void dfs(vector<long long>& vis, vector<long long> adj[], long long u,
         long long& x, long long a) {
  for (long long i = 0; i < adj[u].size(); i++) {
    if (vis[adj[u][i]] == -1) {
      vis[adj[u][i]] = a;
      x++;
      dfs(vis, adj, adj[u][i], x, a);
    }
  }
}
int main() {
  long long m, i, n, j;
  cin >> n >> m;
  vector<long long> adj[n + 1];
  for (i = 0; i < m; i++) {
    long long a;
    cin >> a;
    vector<long long> v(a);
    for (j = 0; j < a; j++) {
      cin >> v[j];
    }
    for (j = 0; j < a; j++) {
      adj[v[j]].push_back(v[(j + 1) % a]);
      adj[v[(j + 1) % a]].push_back(v[j % a]);
    }
  }
  vector<long long> ans(n + 1);
  vector<long long> vis(n + 1, -1);
  long long a;
  for (i = 1; i <= n; i++) {
    if (vis[i] == -1) {
      a = i;
      long long x = 1;
      vis[i] = a;
      dfs(vis, adj, i, x, a);
      ans[i] = x;
      a++;
    } else {
      ans[i] = ans[vis[i]];
    }
  }
  for (i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
}
