#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7;
const double pi = 3.141592653589793238463;
vector<long long int> g[500005];
long long int vis[500005];
long long int dfs(long long int u, long long int p) {
  vis[u] = p;
  long long int sum = 1;
  for (auto &x : g[u]) {
    if (!vis[x]) {
      sum += dfs(x, p);
    }
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  while (m--) {
    long long int k;
    cin >> k;
    vector<long long int> a(k);
    for (long long int i = 0; i < k; i++) {
      cin >> a[i];
    }
    for (long long int i = 1; i < k; i++) {
      g[a[i]].push_back(a[i - 1]);
      g[a[i - 1]].push_back(a[i]);
    }
  }
  for (long long int i = 1; i < n + 1; i++) {
    if (!vis[i]) {
      vis[i] = dfs(i, i);
      cout << vis[i] << ' ';
    } else {
      cout << vis[vis[i]] << ' ';
    }
  }
  return 0;
}
