#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
vector<int> v[maxn];
int n, m;
int fa[maxn];
int fd(int x) { return x == fa[x] ? fa[x] : fa[x] = fd(fa[x]); }
void input() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int k, st, x;
    cin >> k;
    if (k != 0) {
      cin >> st;
      int rt = fd(st);
      for (int t = 1; t < k; t++) {
        cin >> x;
        int fx = fd(x);
        if (fx != rt) fa[fx] = rt;
      }
    }
  }
}
void work() {
  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    int rt = fd(i);
    mp[rt]++;
  }
  for (int i = 1; i <= n; i++) {
    int rt = fd(i);
    cout << mp[rt] << ' ';
  }
  return;
}
int main() {
  input();
  work();
  return 0;
}
