#include <bits/stdc++.h>
const double PI = 3.1415926;
const int KL = 1e6;
using namespace std;
long long q, x, y, z, n, m, p[KL], mn = 1e9, mx = -1e9, ans;
string t;
vector<int> vec[KL];
set<int> s;
map<int, int> M;
int pr[KL], sz[KL];
int prfind(int node) {
  if (pr[node] == node)
    return node;
  else
    return pr[node] = prfind(pr[node]);
}
void make_group(int node1, int node2) {
  int fa1 = prfind(node1);
  int fa2 = prfind(node2);
  if (fa1 == fa2) return;
  if (sz[fa1] >= sz[fa2]) {
    pr[fa2] = fa1;
    sz[fa1] += sz[fa2];
  } else {
    pr[fa1] = fa2;
    sz[fa2] += sz[fa1];
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &x);
    for (int j = 0; j < x; j++) {
      scanf("%d", &y);
      vec[i].push_back(y);
    }
  }
  for (int i = 1; i <= n; i++) {
    pr[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 1; j < vec[i].size(); j++) {
      make_group(vec[i][j], vec[i][j - 1]);
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << sz[prfind(i)] << " ";
  }
  return 0;
}
