#include <bits/stdc++.h>
using namespace std;
template <class T>
void printArray(vector<T> arr) {
  for (T a : arr) cout << a << " ";
  cout << '\n';
}
void printVerdict(bool verdict) { cout << (verdict ? "YES" : "NO") << '\n'; }
void printDecimal(double d) { printf("%.9f\n", d); }
bool inrange(int val, int start, int end) { return val >= start && val <= end; }
template <class T1, class T2, class T3>
void printTuple(tuple<T1, T2, T3> t) {
  cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n';
}
template <class T1, class T2>
void printPair(pair<T1, T2> p) {
  cout << p.first << " " << p.second << '\n';
}
map<int, set<int>> graph;
bool visited[500001];
long long component_size[500001];
int memo[500001];
int cnt = 0, curr_component = 0;
void dfs(int curr, int curr_comp) {
  visited[curr] = true;
  memo[curr] = curr_comp;
  cnt++;
  auto it = graph[curr].begin();
  while (it != graph[curr].end()) {
    if (!visited[*it]) dfs(*it, curr_comp);
    it++;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    if (!k) continue;
    int curr_group[k];
    for (int j = 0; j < k; j++) cin >> curr_group[j];
    for (int j = 0; j < k - 1 && k > 1; j++) {
      graph[curr_group[j]].insert(curr_group[j + 1]);
      graph[curr_group[j + 1]].insert(curr_group[j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    cnt = 0;
    if (!visited[i]) {
      dfs(i, curr_component);
      component_size[curr_component] = cnt;
      curr_component++;
    }
  }
  for (int i = 1; i <= n; i++) cout << component_size[memo[i]] << " ";
  cout << '\n';
}
