#include <bits/stdc++.h>
using namespace std;
const int INT_INF = 1e9;
const long long LL_INF = 2e18;
int n, m;
int par[500002];
int GS[500002], GR[500002];
int findp(int x) { return par[x] == x ? x : par[x] = findp(par[x]); }
void link(int x, int y) {
  x = findp(x), y = findp(y);
  if (x == y) return;
  if (GR[x] > GR[y]) swap(x, y);
  par[x] = y;
  GS[y] += GS[x];
  if (GR[x] == GR[y]) GR[y]++;
}
int k[500002];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    GS[i] = 1;
  }
  for (int i = 0, kn; i < m; i++) {
    scanf("%d", &kn);
    for (int j = 0; j < kn; j++) {
      scanf("%d", &k[j]);
    }
    for (int j = 1; j < kn; j++) {
      link(k[j], k[j - 1]);
    }
  }
  for (int i = 1; i <= n; i++) {
    int pi = findp(i);
    printf("%d ", GS[pi]);
  }
  return 0;
}
