#include <bits/stdc++.h>
using namespace std;
const long long N = 500000;
long long rep[N], rnk[N], a[N];
long long find(long long a) {
  while (a != rep[a]) a = rep[a];
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, m, i, j, k, z, maxi, p1, p2, k1, k2;
  maxi = -1e9;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    rep[i] = i;
    rnk[i] = 1;
  }
  for (i = 0; i < m; i++) {
    cin >> k;
    maxi = -1e9;
    for (j = 0; j < k; j++) cin >> a[j];
    for (j = 0; j < (k - 1); j++) {
      p1 = find(a[j]);
      p2 = find(a[j + 1]);
      if (p1 != p2) {
        k1 = rnk[p1];
        k2 = rnk[p2];
        if (k1 >= k2) {
          rnk[p1] += rnk[p2];
          rep[p2] = p1;
        } else {
          rnk[p2] += rnk[p1];
          rep[p1] = p2;
        }
      }
    }
  }
  for (i = 1; i <= n; i++) cout << rnk[find(i)] << " ";
  cout << endl;
  return 0;
}
