#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 500010;
long long int p[maxn];
long long int sz[maxn];
void init() {
  for (long long int i = 0; i < maxn; i++) {
    p[i] = i;
    sz[i] = 1;
  }
}
long long int findset(long long int x) {
  if (p[x] == x)
    return x;
  else
    return p[x] = findset(p[x]);
}
bool issameset(long long int x, long long int y) {
  long long int a = findset(x);
  long long int b = findset(y);
  return a == b;
}
void joinset(long long int a, long long int b) {
  long long int x = findset(a);
  long long int y = findset(b);
  if (x == y) return;
  p[x] = y;
  sz[y] += sz[x];
}
int main() {
  long long int n, m;
  scanf("%lld %lld", &n, &m);
  init();
  for (long long int i = 0; i < m; i++) {
    long long int k;
    scanf("%lld", &k);
    long long int first = -1;
    for (long long int j = 0; j < k; j++) {
      long long int temp;
      scanf("%lld", &temp);
      if (first == -1) {
        first = temp;
      } else {
        joinset(first, temp);
      }
    }
  }
  for (long long int i = 1; i <= n; i++) {
    printf("%lld ", sz[findset(i)]);
  }
  printf("\n");
}
