#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007;
long long dev[52];
const long long MAXN = 5 * 100000 + 5;
vector<int> lst[MAXN];
int parent[MAXN];
void make_set(int v) {
  lst[v] = vector<int>(1, v);
  parent[v] = v;
}
int find_set(int v) { return parent[v]; }
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (lst[a].size() < lst[b].size()) swap(a, b);
    while (!lst[b].empty()) {
      int v = lst[b].back();
      lst[b].pop_back();
      parent[v] = a;
      lst[a].push_back(v);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    parent[i] = -1;
  }
  for (int i = 0; i < m; ++i) {
    int c;
    cin >> c;
    int ns = -1;
    for (int j = 0; j < c; ++j) {
      int a;
      cin >> a;
      a -= 1;
      auto es = find_set(a);
      if (es == -1) {
        make_set(a);
        if (ns != -1) {
          union_sets(ns, a);
        }
        ns = find_set(a);
      } else {
        if (ns != -1) {
          union_sets(es, ns);
        }
        ns = find_set(a);
      }
    }
  }
  map<int, int> cnt;
  for (int i = 0; i < n; ++i) {
    cnt[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cnt[find_set(i)] += 1;
  }
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    int k = find_set(i);
    if (k != -1) {
      ans.push_back(cnt[find_set(i)]);
    } else {
      ans.push_back(1);
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
