#include <bits/stdc++.h>
using namespace std;
int parent[2000005];
int component[2000005];
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) {
    return;
  }
  if (component[x] < component[y]) {
    swap(x, y);
  }
  component[x] += component[y];
  parent[y] = x;
  return;
}
int main() {
  int n, g;
  cin >> n >> g;
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
    component[i] = 1;
  }
  while (g--) {
    int x;
    cin >> x;
    int last = -1;
    while (x--) {
      int z;
      cin >> z;
      if (last == -1) {
        last = z;
        continue;
      } else {
        uniond(last, z);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int idx = find(i);
    cout << component[idx] << " ";
  }
  cout << endl;
}
