#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 50;
int fa[N], sz[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void link(int x, int y)
{
    int fx = find(x), fy = find(y);
    if (fx != fy)
    {
        fa[fy] = fx;
        sz[fx] += sz[fy];
    }
}
int main()
{
    for (int i = 0; i < N; i++) fa[i] = i, sz[i] = 1;
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0, c, s; i < m; i++)
    {
        scanf("%d", &c);
        if (c == 0) continue;
        scanf("%d", &s);
        for (int i = 1, x; i < c; i++)
            scanf("%d", &x), link(s, x);
    }
    for (int i = 1; i <= n; i++)
        printf("%d ", sz[find(i)]);
    return 0;
}
