#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18;
const long long N = 1e6;
const long long mod = 1e9 + 7;
const double pi = acos(-1);
vector<int> adj[N];
bool visted[N], visted1[N];
map<int, int> mp;
void dfs(int x, int &sum) {
  visted[x] = 1;
  sum++;
  for (auto j : adj[x]) {
    if (!visted[j]) dfs(j, sum);
  }
}
void dfs1(int x, int &sum) {
  visted1[x] = 1;
  mp[x] = sum;
  for (auto j : adj[x]) {
    if (!visted1[j]) dfs1(j, sum);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    int a[k];
    for (int j = 0; j < k; j++) {
      cin >> a[j];
      if (j) {
        adj[a[j]].push_back(a[j - 1]);
        adj[a[j - 1]].push_back(a[j]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    if (!visted[i]) {
      dfs(i, sum);
      dfs1(i, sum);
    }
  }
  for (int i = 1; i <= n; i++) cout << mp[i] << " ";
  return 0;
}
