#include <bits/stdc++.h>
using namespace std;
long long int n, m;
vector<long long int> parent, ranks;
long long int find(long long int a) {
  if (parent[a] == -1) return a;
  parent[a] = find(parent[a]);
  return parent[a];
}
void union_set(long long int a, long long int b) {
  long long int s1 = find(a), s2 = find(b);
  if (s1 != s2) {
    if (ranks[s1] > ranks[s2]) {
      parent[s2] = s1;
      ranks[s1] += ranks[s2];
    } else {
      parent[s1] = s2;
      ranks[s2] += ranks[s1];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  parent.resize(n, -1);
  ranks.resize(n, 1);
  long long int i, j, a, b, k;
  for (i = 0; i < m; i++) {
    cin >> k;
    vector<long long int> friends(k);
    for (j = 0; j < k; j++) {
      cin >> a;
      a--;
      friends[j] = a;
    }
    for (j = 0; j < k - 1; j++) {
      a = friends[j];
      b = friends[j + 1];
      union_set(a, b);
    }
  }
  for (i = 0; i < n; i++) {
    cout << ranks[find(i)] << " ";
  }
}
