#include <bits/stdc++.h>
using namespace std;
int parent[1000007];
int components[1000007];
int find(int a) {
  if (parent[a] == a) {
    return a;
  }
  return find(parent[a]);
}
void uniond(int a, int b) {
  int x = find(a);
  int y = find(b);
  if (x != y) {
    if (components[x] < components[y]) {
      swap(x, y);
    }
    parent[y] = x;
    components[x] = components[x] + components[y];
  }
  return;
}
int main() {
  int n, e;
  cin >> n >> e;
  int d;
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
    components[i] = 1;
  }
  for (int i = 0; i < e; i++) {
    cin >> d;
    vector<int> v;
    for (int j = 0; j < d; j++) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    for (int j = 1; j < d; j++) {
      uniond(v[j], v[j - 1]);
    }
    v.clear();
  }
  for (int i = 1; i <= n; i++) {
    cout << abs(components[find(i)]) << " ";
  }
  cout << endl;
  return 0;
}
