#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <memory.h>

const int NMAX = 10000;
short unsigned int A[NMAX][NMAX];

int main () {
    freopen("theatre.in", "r", stdin);
    freopen("theatre.out", "w", stdout);
    memset(A, 255, sizeof A);
    std::ios_base::sync_with_stdio(false);
    size_t n, m;
    std::cin >> n >> m;
    std::vector<char> isTakePart(n, false);
    for(size_t step = 0; step < m; ++step) {
        size_t k;
        std::cin >> k;
        std::vector<int> performance;
        performance.reserve(k);
        for(size_t t = 0; t < k; ++t) {
            size_t user;
            std::cin >> user;
            --user;
            performance.push_back(user);
            isTakePart[user] = true;
        }
        for(size_t t = 0; t < k; ++t) {
            for(size_t i = 0; i < n; ++i) if (!isTakePart[i]) {
                size_t j = performance[t];
                if (A[j][i] > step) {
                    A[j][i] = A[i][j] = step;
                }
            }
        }
        for(size_t t = 0; t < k; ++t) {
            isTakePart[performance[t]] = false;
        }
    }

    for(size_t i = 0; i < n; ++i) {
        unsigned short int ans = 0;
        for(size_t j = 0; j < n; ++j) if (i != j) {
            ans = std::max(ans, A[i][j]);
        }
        ++ans;

        if (i > 0) std::cout << " ";
        std::cout << ans;
    }
    std::cout << std::endl;

    return 0;
}

