#include <cstdio>
#include <iostream>
#include <vector>
#include <bitset>

const int NMAX = 10000;
std::bitset<NMAX> A[NMAX];


int main () {
    freopen("theatre.in", "r", stdin);
    freopen("theatre.out", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    size_t n, m;
    std::cin >> n >> m;
    std::vector<char> isTakePart(n, false);
    std::vector<size_t> ans(n, 0), count(n, 0);
    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[i].test(j)) {
                    A[i].set(j);
                    A[j].set(i);
                    ++count[i];
                    ++count[j];
                    ans[i] = std::max(ans[i], step);
                    ans[j] = std::max(ans[j], step);
                }
            }
        }
        for(size_t t = 0; t < k; ++t) {
            isTakePart[performance[t]] = false;
        }
    }

    for(size_t i = 0; i < n; ++i) {
        if (i > 0) std::cout << " ";
        std::cout << (count[i] == n - 1 ? ans[i] + 1 : 0);
    }
    std::cout << std::endl;

    return 0;
}

