#include <bits/stdc++.h>
using namespace std;
int find(int x, int par[]) {
  while (x != par[x]) x = par[x];
  return x;
}
void join(int a, int b, int par[], int size[]) {
  a = find(a, par);
  b = find(b, par);
  if (a == b) return;
  if (size[a] < size[b]) swap(a, b);
  size[a] += size[b];
  par[b] = a;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int test = 1;
  while (test--) {
    int n, m;
    cin >> n >> m;
    int size[m + 1];
    int par[m + 1];
    for (int i = 0; i <= m; i++) {
      par[i] = i;
      size[i] = 1;
    }
    vector<int> a[n + 1];
    for (int i = 0; i < m; i++) {
      int len;
      cin >> len;
      for (int j = 0; j < len; j++) {
        int z;
        cin >> z;
        a[z].push_back(i);
      }
    }
    for (int i = 1; i <= n; i++) {
      int la = a[i].size();
      for (int j = 0; j < la - 1; j++) {
        join(a[i][j], a[i][j + 1], par, size);
      }
    }
    map<int, int> mp;
    for (int i = 1; i <= n; i++) {
      if (a[i].size() == 0) continue;
      mp[find(a[i][0], par)]++;
    }
    for (int i = 1; i <= n; i++) {
      if (a[i].size() == 0)
        cout << 1 << " ";
      else
        cout << mp[find(a[i][0], par)] << " ";
    }
  }
  return 0;
}
