#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int MAX = 2 * 1000 * 1000 + 10;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
int parent[MAX], size[MAX];
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void make_set() {
  for (int i = 0; i < MAX; i++) {
    parent[i] = i;
    size[i] = 1;
  }
}
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() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  make_set();
  for (int j = 0; j < m; j++) {
    int x, y, t;
    cin >> x;
    if (x) {
      cin >> y;
    }
    for (int i = 1; i < x; i++) {
      cin >> t;
      union_sets(y, t);
    }
  }
  for (int i = 1; i <= n; i++) {
    int p = find_set(i);
    cout << size[p] << " ";
  }
  cout << '\n';
}
