#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
long long a[N], parent[N], f[N], r[N];
bool vis[N], vis1[N];
vector<long long> v, v1;
pair<long long, string> p[N], p1[N];
set<long long> s, s1;
map<long long, long long> mp, mp1;
queue<long long> q;
long long mod = 1e9 + 7;
void make_set(int v) { parent[v] = v; }
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (r[a] < r[b]) swap(a, b);
    parent[b] = a;
    if (r[a] == r[b]) r[a]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  int n, m, k;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) make_set(i);
  for (int i = 0; i < m; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> a[j];
      union_sets(a[0], a[j]);
    }
  }
  for (int i = 1; i <= n; i++) f[find_set(i)]++;
  for (int i = 1; i <= n; i++) cout << f[find_set(i)] << " ";
}
