#include <bits/stdc++.h>
using namespace std;
int dcmp(long double x, long double y) {
  return fabs(x - y) <= 1e-9 ? 0 : x < y ? -1 : 1;
}
const int MAX = 5e5 + 10;
const long long MOD = 1e9 + 7;
class UnionFind {
 private:
  vector<int> p, rank, setSize;
  int numSets;

 public:
  UnionFind(int N) {
    setSize.assign(N, 1);
    numSets = N;
    rank.assign(N, 0);
    p.assign(N, 0);
    for (int i = 0; i < N; i++) p[i] = i;
  }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) {
    if (!isSameSet(i, j)) {
      numSets--;
      int x = findSet(i), y = findSet(j);
      if (rank[x] > rank[y]) {
        p[y] = x;
        setSize[x] += setSize[y];
      } else {
        p[x] = y;
        setSize[y] += setSize[x];
        if (rank[x] == rank[y]) rank[y]++;
      }
    }
  }
  int numDisjointSets() { return numSets; }
  int sizeOfSet(int i) { return setSize[findSet(i)]; }
};
void solve();
void read();
void clear();
int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
}
void read() {}
void solve() {
  cin >> n >> m;
  UnionFind dsu = UnionFind(n + 1);
  for (int i = 0; i < (int)(m); ++i) {
    int siz;
    cin >> siz;
    int last = -1;
    for (int j = 0; j < (int)(siz); ++j) {
      int u;
      cin >> u;
      if (last != -1) {
        dsu.unionSet(u, last);
      }
      last = u;
    }
  }
  for (int i = 0; i < (int)(n); ++i) {
    cout << dsu.sizeOfSet(i + 1) << ' ';
  }
  cout << '\n';
}
