#include <bits/stdc++.h>
using namespace std;
inline long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
inline long long int lcm(long long int a, long long int b) {
  return (a / gcd(a, b) * b);
}
inline bool isPrime(long long int n) {
  long long int i;
  for (i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
const long long int mod = 1000000007;
vector<int> adj[1000001];
bool visited[1000001];
long long int number[1000001];
int c = 0;
void dfs(int n, vector<long long int> &v) {
  c++;
  visited[n] = true;
  v.push_back(n);
  for (auto it : adj[n])
    if (!visited[it]) {
      dfs(it, v);
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    for (long long int i = 1; i <= n; i++) visited[i] = false;
    while (m--) {
      long long int k;
      cin >> k;
      std::vector<long long int> v(k);
      for (long long int i = 0; i < k; ++i) cin >> v[i];
      ;
      for (long long int i = 0; i < k - 1; i++) {
        adj[v[i]].push_back(v[i + 1]);
        adj[v[i + 1]].push_back(v[i]);
      }
    }
    for (long long int i = 1; i <= n; i++) {
      vector<long long int> v;
      if (!visited[i]) {
        c = 0;
        dfs(i, v);
        for (auto it : v) number[it] = c;
      }
    }
    for (long long int i = 1; i <= n; i++) {
      cout << number[i] << " ";
    }
  }
}
