#include <bits/stdc++.h>
using namespace std;
vector<int> ar[500005];
int n, m, x, g, depth = 1;
int visited[500005];
void dfs1(int ind) {
  visited[ind] = 1;
  for (int k = 0; k < ar[ind].size(); k++) {
    if (visited[ar[ind][k]] == 0) {
      depth++;
      dfs1(ar[ind][k]);
    }
  }
  return;
}
void dfs2(int ind) {
  for (int k = 0; k < ar[ind].size(); k++) {
    if (visited[ar[ind][k]] == 1) {
      visited[ar[ind][k]] = depth;
      dfs2(ar[ind][k]);
    }
  }
  return;
}
int main() {
  int first;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> g;
    if (g != 0) {
      cin >> first;
      for (int j = 1; j < g; j++) {
        cin >> x;
        ar[first].push_back(x);
        ar[x].push_back(first);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      dfs1(i);
      dfs2(i);
      depth = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << visited[i] << " ";
  }
  cout << endl;
}
