#include <bits/stdc++.h>
using namespace std;
const long long MAX = 600000;
long long par[MAX];
long long rankk[MAX];
long long sum[MAX];
void init(long long n) {
  for (long long i = 0; i < n; i++) {
    par[i] = i;
    rankk[i] = 0;
    sum[i] = 1;
  }
}
long long find(long long x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unit(long long x, long long y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rankk[x] < rankk[y]) {
    par[x] = y;
    sum[y] += sum[x];
  } else {
    par[y] = x;
    sum[x] += sum[y];
    if (rankk[x] == rankk[y]) rankk[x]++;
  }
}
bool same(long long x, long long y) { return find(x) == find(y); }
int main() {
  long long n, m;
  cin >> n >> m;
  init(n + 10);
  for (long long i = 0; i < m; i++) {
    long long k, a, b;
    cin >> k;
    if (k) cin >> a;
    for (long long j = 1; j < k; j++) {
      cin >> b;
      unit(a, b);
      a = b;
    }
  }
  cout << sum[find(1)];
  for (long long i = 2; i <= n; i++) {
    cout << " " << sum[find(i)];
  }
  return 0;
}
