#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 100009;
int pa[N], sz[N];
int find(int x) {
  if (pa[x] == x) return x;
  return find(pa[x]);
}
void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (sz[y] > sz[x]) swap(x, y);
  sz[x] += sz[y];
  pa[y] = x;
}
int main() {
  int x, y;
  int last;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    sz[i] = 1;
    pa[i] = i;
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    for (int j = 0; j < x; j++) {
      cin >> y;
      if (j == 0) {
        last = y;
        continue;
      };
      merge(y, last);
      last = y;
    }
  }
  for (int i = 1; i < n + 1; i++) cout << sz[find(i)] << " ";
}
