#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long MAX = 100010LL;
template <typename T>
T power(T x, T y, long long m = MOD) {
  T ans = 1;
  x %= m;
  while (y > 0) {
    if (y & 1LL) ans = (ans * x) % m;
    y >>= 1LL;
    x = (x * x) % m;
  }
  return ans % m;
}
long long n, m;
vector<vector<long long> > v(500005);
long long vis[500005];
long long reach[500005];
long long col;
long long dfs(long long c) {
  vis[c] = col;
  long long cnt = 1;
  for (long long i = 0; i < v[c].size(); i++) {
    if (!vis[v[c][i]]) {
      cnt += dfs(v[c][i]);
    }
  }
  return reach[c] = cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long k;
  memset(reach, 0, sizeof(reach));
  memset(vis, 0, sizeof(vis));
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> k;
    if (k == 0)
      continue;
    else if (k == 1)
      cin >> x;
    else {
      cin >> x;
      for (long long i = 0; i < k - 1; i++) {
        cin >> y;
        v[x].push_back(y);
        v[y].push_back(x);
      }
    }
  }
  long long a[n + 1];
  col = 1;
  map<long long, long long> sz;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      long long c = dfs(i);
      sz[col] = c;
      col++;
    }
    cout << sz[vis[i]] << " ";
  }
  cout << "\n";
  return 0;
}
