#include <bits/stdc++.h>
using namespace std;
int findParent(int i, vector<int> &parent) {
  if (parent[parent[i]] != parent[i]) parent[i] = findParent(parent[i], parent);
  return parent[i];
}
void unionNodes(int nodeA, int nodeB, vector<int> &parent, vector<int> &size) {
  int parentA = findParent(nodeA, parent);
  int parentB = findParent(nodeB, parent);
  if (parentA == parentB) return;
  if (size[parentA] >= size[parentB]) {
    size[parentA] += size[parentB];
    parent[parentB] = parentA;
  } else {
    size[parentB] += size[parentA];
    parent[parentA] = parentB;
  }
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> parents(n + 1, 0);
  vector<int> size(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    parents[i] = i;
    size[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    vector<int> connectedNodes;
    for (int j = 0; j < k; j++) {
      int temp;
      cin >> temp;
      connectedNodes.push_back(temp);
    }
    for (int j = 0; j < k - 1; j++) {
      unionNodes(connectedNodes[j], connectedNodes[j + 1], parents, size);
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << size[findParent(i, parents)] << " ";
  }
  cout << endl;
  return 0;
}
