#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 5e5 + 5;
int F[maxn];
int sum[maxn];
int findz(int x) { return F[x] = F[x] == x ? F[x] : findz(F[x]); }
void Union(int x, int y) {
  int fa = findz(x);
  int fb = findz(y);
  if (fa != fb) F[fb] = fa, sum[fa] += sum[fb];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) F[i] = i, sum[i] = 1;
  for (int i = 1; i <= m; i++) {
    int num;
    cin >> num;
    int s;
    int last = -1;
    for (int j = 1; j <= num; j++) {
      cin >> s;
      if (last == -1)
        last = s;
      else {
        Union(s, last);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int fa = findz(i);
    cout << sum[fa] << endl;
  }
}
