#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> gra[n];
  vector<int> v;
  int k, fr;
  for (int i = 0; i < m; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> fr;
      v.push_back(fr - 1);
    }
    for (int j = 0; j < k - 1; j++) {
      gra[v[j]].push_back(v[j + 1]);
      gra[v[j + 1]].push_back(v[j]);
    }
    v.clear();
  }
  bool vit[n];
  vector<vector<int>> arr;
  vector<int> vec;
  for (int q = 0; q < n; q++) vit[q] = false;
  for (int i = 0; i < n; i++) {
    if (vit[i] == false) {
      vit[i] = true;
      stack<int> s;
      s.push(i);
      vec.push_back(i);
      while (!s.empty()) {
        int front = s.top();
        s.pop();
        for (int k = 0; k < gra[front].size(); k++) {
          if (vit[gra[front][k]] != true) {
            s.push(gra[front][k]);
            vit[gra[front][k]] = true;
            vec.push_back(gra[front][k]);
          }
        }
      }
    }
    arr.push_back(vec);
    vec.clear();
  }
  int ara[n];
  for (int i = 0; i < arr.size(); i++) {
    for (int j = 0; j < arr[i].size(); j++) {
      ara[arr[i][j]] = arr[i].size();
    }
  }
  for (int i = 0; i < n; i++) cout << ara[i] << " ";
  return 0;
}
