#include <bits/stdc++.h>
using namespace std;
long long int total[500005];
long long int par[500005];
long long int F(long long int x) {
  if (par[x] == x) return x;
  return par[x] = F(par[x]);
}
void U(long long int a, long long int b) {
  long long int u = F(a);
  long long int v = F(b);
  if (u == v) return;
  par[u] = v;
  total[v] += total[u];
}
int main() {
  long long int t = 0, n, m, e, x, y, z, i, j, k, g, q, ans = 1e18, sum = 0,
                c = 0, h;
  string s;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    par[i] = i;
    total[i] = 1;
  }
  for (i = 1; i <= m; i++) {
    cin >> k;
    for (j = 1; j <= k; j++) {
      cin >> x;
      if (j == 1)
        y = x;
      else
        U(x, y);
      y = x;
    }
  }
  for (i = 1; i <= n; i++) {
    x = F(i);
    cout << total[par[i]] << " ";
  }
  cout << endl;
  return 0;
}
