#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int M = 1e7 + 10;
const long long mod = 1e9 + 7;
int parentOf[N];
int sizeoF[N];
int findParent(int x) {
  if (x == parentOf[x]) return x;
  return parentOf[x] = findParent(parentOf[x]);
}
void unite(int a, int b) {
  int ra, rb;
  ra = findParent(a);
  rb = findParent(b);
  if (ra == rb) return;
  if (sizeoF[ra] < sizeoF[rb]) {
    parentOf[ra] = parentOf[rb];
    sizeoF[rb] += sizeoF[ra];
  } else {
    parentOf[rb] = parentOf[ra];
    sizeoF[ra] += sizeoF[rb];
  }
}
int main() {
  for (long long i = 0; i < N; i++) parentOf[i] = i, sizeoF[i] = 1;
  int n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    int k;
    cin >> k;
    if (k) {
      int first;
      cin >> first;
      for (long long j = 0; j < k - 1; j++) {
        int a;
        cin >> a;
        unite(a, first);
      }
    }
  }
  for (int i = 1; i <= n; i++) cout << sizeoF[findParent(i)] << " ";
  return 0;
}
