#include <bits/stdc++.h>
using namespace std;
class dsu {
  int* par;
  int n;
  int* size;

 public:
  dsu(int x) {
    n = x;
    par = new int[x + 1];
    size = new int[x + 1];
    for (int i = 1; i <= n; i++) {
      par[i] = i;
      size[i] = 1;
    }
  }
  int getPar(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = getPar(par[x]);
  }
  void unite(int x, int y) {
    x = getPar(x);
    y = getPar(y);
    if (x != y) par[x] = y, size[y] += size[x];
  }
  int getSize(int x) {
    x = getPar(x);
    return size[x];
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  dsu g(n);
  for (int i = 1; i <= m; i++) {
    int k;
    cin >> k;
    vector<int> nd(k);
    for (int j = 0; j < k; j++) {
      cin >> nd[j];
    }
    for (int j = 1; j < k; j++) {
      g.unite(nd[j - 1], nd[j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << g.getSize(i) << " ";
  }
}
int main() { solve(); }
