#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 public:
  vector<int> father;
  vector<int> sum;
  UnionFind(int num) {
    for (int i = 0; i < num; i++) {
      father.push_back(i);
    }
    for (int i = 0; i < num; i++) {
      sum.push_back(1);
    }
  }
  int Find(int x) {
    if (father[x] == x) return x;
    return father[x] = Find(father[x]);
  }
  void Union(int x, int y) {
    x = Find(x), y = Find(y);
    if (x == y) return;
    if (sum[x] >= sum[y]) {
      father[y] = x;
      sum[x] += sum[y];
    } else {
      father[x] = y;
      sum[y] += sum[x];
    }
  }
};
int main() {
  int n, m, t, head, x;
  scanf("%d%d", &n, &m);
  UnionFind u(n + 1);
  for (int i = 0; i < m; i++) {
    scanf("%d", &t);
    for (int j = 0; j < t; j++) {
      if (j) {
        scanf("%d", &x);
        u.Union(head, x);
      } else
        scanf("%d", &head);
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", u.sum[u.Find(i + 1)]);
  }
  return 0;
}
