#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 * 100 * 1000 + 3;
int n, m, k;
vector<int> group[MAXN];
vector<int> adj[MAXN];
vector<int> child[MAXN];
map<int, int> mp, mpp;
int ans[MAXN];
bool mark[MAXN], p[MAXN];
int h;
int f;
void dfs(int u) {
  mark[u] = true;
  mp[u] = h;
  for (int t = 0; t < child[u].size(); t++) {
    if (!p[child[u][t]]) {
      p[child[u][t]] = true;
      f++;
    }
  }
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (!mark[v]) {
      dfs(v);
    }
  }
  return;
}
void dfs_all() {
  for (int i = 0; i < m; i++) {
    if (!mark[i]) {
      h++;
      f = 0;
      dfs(i);
      mpp[h] = f;
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      int x;
      cin >> x;
      x--;
      child[i].push_back(x);
      if (group[x].size() != 0) {
        adj[group[x].back()].push_back(i);
        adj[i].push_back(group[x].back());
      }
      group[x].push_back(i);
    }
  }
  dfs_all();
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < child[i].size(); j++) {
      ans[child[i][j]] = mpp[mp[i]];
    }
  }
  for (int i = 0; i < n; i++) {
    cout << max(ans[i], 1) << " ";
  }
  return 0;
}
