#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n, m, second;
std::vector<int> parent, size, used;
void make_set(int v) {
  parent[v] = v;
  size[v] = 1;
}
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 (size[a] < size[b]) swap(a, b);
    parent[b] = a;
    size[a] += size[b];
  }
}
int main() {
  cin >> n >> m;
  parent.resize(n + 1, 0);
  size.resize(n + 1, 0);
  used.resize(n + 1, 0);
  for (int i = 0; i < m; ++i) {
    cin >> second;
    int first = -1;
    for (int j = 0, x; j < second; ++j) {
      cin >> x;
      if (!used[x]) make_set(x), used[x] = 1;
      if (first == -1) first = x;
      union_sets(x, first);
    }
  }
  for (int i = 1; i <= n; ++i) {
    int ans = find_set(i);
    if (!ans)
      cout << 1 << " ";
    else
      cout << size[ans] << " ";
  }
  cout << endl;
}
