#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void f(long long a[], long long n) {
  long long i, j;
  for (i = 1; i <= n; i++) a[i] = 1;
  for (i = 2; i * i <= n; i++) {
    if (a[i]) {
      for (j = 2 * i; j <= n; j += i) a[j] = 0;
    }
  }
}
long long getprime(long long n) {
  if (n == 1) return 0;
  for (long long i = 2; i <= n / i; i++)
    if (n % i == 0) return 1;
  return 0;
}
const int MAXN = 5e5 + 54;
int fa[MAXN], r[MAXN];
int findfa(int x) { return x == fa[x] ? x : fa[x] = findfa(fa[x]); }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    r[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int x, la = -1, p;
    scanf("%d", &x);
    for (int j = 1; j <= x; j++) {
      scanf("%d", &p);
      if (la != -1) {
        int fla = findfa(la);
        int fp = findfa(p);
        if (fp != fla) {
          fa[fla] = fp;
          r[fp] += r[fla];
        }
      }
      la = p;
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", r[findfa(i)]);
  }
}
